Wednesday, July 28, 2021

#1 2007-10-31 02:00:11 pm

George Washington
Member
Registered: 2007-08-13
Posts: 56

Script Stalling using Curl Command

Here's my script:

Applescript:


set trackNum to <a tracking number>
set fedexURL to "[url]http://www.fedex.com/Tracking?language=english&cntry_code=us&tracknumbers=[/url]"
set whoSigned to do shell script "curl -A \"Mozilla/4.0\" -s " & fedexURL & trackNum (*& " | awk '/Signed for by / {print $4}' | cut -f 1 -d '<' "*)

Here's my problem:

Applescript stops responding everytime I run this command.  It doesn't even work using just the fedexURL Url (so if you can't think of a tracking number to put in there, curl isn't even opening that page).  Yet I am able to get this to work going to just "http://www.fedex.com".

Why is Applescript stalling and not responding everytime it tries to curl:
"http://www.fedex.com/Tracking?language= … cknumbers="


Any suggestions? Is there something super secret going on behind fedex's webpage preventing curl lookups?

I know everyone is excited about leopard, but hopefully this won't get lost in all the leopard questions.

Offline

 

#2 2007-10-31 02:09:55 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11749
Website

Re: Script Stalling using Curl Command

Hi George,

try

Applescript:


set whoSigned to do shell script "curl -A \"Mozilla/4.0\" -s " & quoted form of (fedexURL & trackNum) (*& " | awk '/Signed for by / {print $4}' | cut -f 1 -d '<' "*)

you should use quoted form always in strings containing spaces and other special characters (like & and ?)

Last edited by StefanK (2007-10-31 02:10:18 pm)


regards

Stefan

Offline

 

#3 2007-10-31 05:21:12 pm

George Washington
Member
Registered: 2007-08-13
Posts: 56

Re: Script Stalling using Curl Command

Ah, yes that worked. Thanks Stefan!  I should have picked up on that sometime before, I've seen you and Bruce doing that with curl commands.

I'm almost embarrased to ask, but I apparently have no talent in awk's and greps.  how would I parse this text to get the who signed for?

this is what it looks like

       <TR vAlign="top" bgColor="#e6e6e6">
              <TD><B>Signed for by</B></TD>
              <TD><BR></TD>
              <TD>G. Washington</TD>
              <TD><BR></TD>
            </TR>

so far, I've been using AWK to get text right next to  key words.  Like I know how to get the "for by" after "Signed" but since the name I'm looking for isn't on the same line, but instead below, my 'key words', I don't know how to do that.  Any suggestions?

Offline

 

#4 2007-10-31 07:18:03 pm

Bruce Phillips
Administrator
Registered: 2004-07-16
Posts: 2649

Re: Script Stalling using Curl Command

Try something like this:

Applescript:

do shell script "/usr/bin/curl -A \"Mozilla/4.0\" -s " & quoted form of (fedexURL & trackNum) & ¬
   " | /usr/bin/grep --max-count=1 --context=2 'Signed for by'" & ¬
   " | /usr/bin/grep '<TD>[^<]*</TD>'" & ¬
   " | /usr/bin/sed -e 's/ *<TD>//' -e 's/<\\/TD>//'"
set whoSigned to result

Edit: Alternatively:

Applescript:

do shell script "/usr/bin/curl -A \"Mozilla/4.0\" -s " & quoted form of (fedexURL & trackNum) & ¬
   " | /usr/bin/grep --max-count=1 --context=2 'Signed for by'"
set whoSigned to result

set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to "<TD>"
try
   set whoSigned to text 1 thru -6 of last text item of whoSigned
on error
   set whoSigned to ""
end try
set AppleScript's text item delimiters to ASTID

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)