Download URL to variable

In the dictionary for URL Access Scripting it appears that a URL must always be downloaded to a file as in:

tell application "URL Access Scripting"
	download target_URL to file destination_file replacing yes
end tell

Is there any way to download a URL directly to a variable as text, bypassing the necessity for opening a file as text and working with it?

Use curl:

set the_HTML to my get_url("http://www.apple.com")

on get_url(this_url)
	set browser_string to "'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/125.4 (KHTML, like Gecko) Safari/125.9'"
	return do shell script "curl " & (quoted form of this_url) & " -A " & browser_string
end get_url

Jon

I get this error:

curl: (7) Failed to connect to [url=http://www.apple.com]www.apple.com[/url] IP number 1: 61

It does this with or without the “the quoted form of” condition. Why is it truncating the address to www.apple.com? I get the same error if I substitute a numerical IP address, so it isn’t that. Error 61 is “Unrecognized transfer encoding”

Hmm, I don’t get any errors on Mac OS 10.3.8. Can any one else test this code?

Jon

The code work perfectly for me, the result was the same HTML code that I see when I view the source of www.apple.com in my browser.

jON bEEBE

Ugh. :cry: I’m running 10.3.8 as well. My favorite kind of error - unique to my system. I have no idea where to go from here. Could it be because I’m not using Safari as my default browser? (Nope - I tried switching)

Turns out, as I’m sure most readers figured before I did, that this is a problem with my user account. If I run the same code in another account on the same machine it works like a charm. Now to figure out what’s screwing it up in my account!

You may try this one

set toto to do shell script "/usr/bin/curl http://google.com"

Returns :
“ blah blah blah ”

Model: PowerBOOK 17" (the very old one)
AppleScript: 1.10.6
Browser: Firefox 1.5.0.4
Operating System: Mac OS X (10.4)

If you’re using Safari, you can use this:

tell application "Safari"
	set webaddress to URL of document 1
end tell