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("")

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


I get this error:

curl: (7) Failed to connect to [url=][/url] IP number 1: 61

It does this with or without the “the quoted form of” condition. Why is it truncating the address to 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?


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


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"

Returns :
“ blah blah blah ”

Model: PowerBOOK 17" (the very old one)
AppleScript: 1.10.6
Browser: Firefox
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