LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-31-2008, 11:53 AM   #1
xmrkite
Member
 
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554

Rep: Reputation: 30
Help me extract some info from a web page


Hello, i need to extract some info from the fedex web page so that we can view tracking info in a somewhat automated way.

For example, if you go to this page: http://www.fedex.com/Tracking?langua...s=799243830729

We need to extract the status, ship date, and the delivery date out of that file so we can check and make sure fedex delivered on time.

I'm sure it's possible with grep and sed, but i just don't really know how to use them well.

Let me know if anyone has any ideas or tips. Code is welcome. Hopefully a simple bash script will be able to do this.

-Thanks
 
Old 01-31-2008, 01:05 PM   #2
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
That was fun

This could probably be better in perl than bash, and the formatting is a bit patchy and a bit of a hack. You need to try out a few different tracking numbers really.

Code:
#!/bin/bash

 echo -n "Tracking Number: "
 read track

 links -dump "http://www.fedex.com/Tracking?language=english&cntry_code=us&tracknumbers=$track" | grep Delivered | sed  's/by\ using//' | sed 's/Checker.//' | sed 's/Go\ to//'
 
Old 01-31-2008, 01:20 PM   #3
xmrkite
Member
 
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554

Original Poster
Rep: Reputation: 30
Thanks for the reply, but that doesn't give any dates for when it was shipped and when it was delivered. Any ideas?
-Thanks
 
Old 01-31-2008, 03:19 PM   #4
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
Code:
 #!/bin/bash

 echo -n "Tracking Number: "
 read track

 delivdate=`links -dump "http://www.fedex.com/Tracking?language=english&cntry_code=us&tracknumbers=$track" | grep "Delivery date"`
 delivtime=`links -dump "http://www.fedex.com/Tracking?language=english&cntry_code=us&tracknumbers=$track" | grep "Weight" | sed 's/Address//'`
 shipdate=`links -dump "http://www.fedex.com/Tracking?language=english&cntry_code=us&tracknumbers=$track" | grep "Ship date" | sed 's/by\ using//'`
 echo $delivdate$delivtime
 echo $shipdate
If you look at the whole output from links then add your own greps and seds for the parts you want it's quite simple.
man grep
man sed
for more info.
 
Old 01-31-2008, 03:54 PM   #5
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
To be a little nicer to FedEx:
Code:
#!/bin/bash

echo -n "Tracking Number: "
read track
fedexpage=`links -dump "http://www.fedex.com/Tracking?language=english&cntry_code=us&tracknumbers=$track"`
delivdate=`echo $fedexpage | grep "Delivery date"`
delivtime=`echo $fedexpage | grep "Weight" | sed 's/Address//'`
shipdate=`echo $fedexpage | grep "Ship date" | sed 's/by\ using//'`
echo $delivdate$delivtime
echo $shipdate
This isn't working properly, but I'll try to fix it.

HTH

Forrest

Last edited by forrestt; 01-31-2008 at 03:56 PM.
 
Old 01-31-2008, 04:07 PM   #6
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
This does the trick:
Code:
#!/bin/bash

echo -n "Tracking Number: "
read track
links -dump "http://www.fedex.com/Tracking?language=english&cntry_code=us&tracknumbers=$track" > /tmp/$track
delivdate=`grep "Delivery date" /tmp/$track`
delivtime=`grep "Weight" /tmp/$track | sed 's/Address//'`
shipdate=`grep "Ship date" /tmp/$track | sed 's/by\ using//'`
echo $delivdate$delivtime
echo $shipdate
rm /tmp/$track
HTH

Forrest
 
Old 01-31-2008, 07:11 PM   #7
xmrkite
Member
 
Registered: Oct 2006
Location: California, USA
Distribution: Mint 16, Lubuntu 14.04, Mythbuntu 14.04, Kubuntu 13.10, Xubuntu 10.04
Posts: 554

Original Poster
Rep: Reputation: 30
Wow, you guys rock. These work great. Thank so much for the help. That was about as quick as they come...less than 5 hours after my initial post.

-Thanks
-Steve
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract "itemTitle" from ebay web page DIMonS Programming 6 11-06-2007 06:36 AM
"info ls" shows man page instead of info page lorenz Slackware 8 09-21-2007 08:47 PM
ftp video files - cron job extracts video info & posts to web page? muskiediver Linux - General 6 11-23-2006 08:41 AM
How can I extract urchin bandwidth info? spiffytech Linux - Software 0 02-16-2006 12:10 PM
Need to extract info out of a binary file synapse Programming 6 09-27-2005 04:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 02:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration