Script Stalling using Curl Command

Here’s my script:


set trackNum to <a tracking number>
set fedexURL to "http://www.fedex.com/Tracking?language=english&cntry_code=us&tracknumbers="
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=english&cntry_code=us&tracknumbers=

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.

Hi George,

try


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 ?)

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?

Try something like this:

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:

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