Grab remote HTML file?


Is there any way to grab the contents of a remote HTML file within AppleScript?

~ Tom

do shell script "/usr/bin/curl " & quoted form of ""

If you extend your definition of “within AppleScript” to include a shell script, and your definition of “contents” to mean the HTML of a page, then this will work. I use the example as the front end of a script that gets US/Canadian dollar exchange rates. Stick your target HTML after the curl.

set HTM to do shell script "curl [url=]"[/url]

Thanks! Sorry, I’m a new AppleScript user, so I wasn’t completely sure of the terminology. :slight_smile:

Not to worry - I just wasn’t sure I was answering your question. I don’t know what you want to do with the contents, but after you’ve got the site page as a variable in your script, it’s very easy to parse out of it any data you want.

This is how I check my external IP (outside the router):

-- Using 
property oldIP : "xx.yy.zz.aa" -- your current (or any) IP here
set theHTML to do shell script "curl"
set myIP to word 25 of theHTML
if myIP = oldIP then
	set myTitle to "No Change in IP Address" & return & return
	set Msg to "It remains " & myIP
	set myTitle to "IP Address Changed!" & return & return
	set Msg to "Now " & myIP
	set oldIP to (myIP as text)
end if

display dialog myTitle & Msg

If you save this as an application, the property oldIP will hold from run to run (it is reset to the value you enter here every time you compile the script, but saves the value it gets in the set oldIP if not recompiled).

I just added something like that to Get External IP Address (v1.1), but I did it differently. (This was after seeing you mention it, Adam. :cool:)