A script that clicks a dynamic link

I’m wondering if it’s possible for Applescript to open this link:


and then click the daily changing link

“Watch entire show - broadband or dialup”


Hi ronan,

try this

set site_url to "http://democracynow.org/streampage.pl"
set link_text to "Watch entire show - broadband or dialup"
tell application "Safari"
	open location site_url
	if my page_loaded(20) is false then return
	set theLink to my find_link(link_text)
	if theLink is false then -- link text not found
		display dialog "Link \"" & link_text & "\" not found."
		open location theLink
	end if
end tell
on find_link(link)
	tell application "Safari" to set num_links to (do JavaScript "document.links.length" in document 1)
	-- find the link
	set c to num_links - 1
	set this_link to ""
	set f to false
	repeat with i from 0 to c
		tell application "Safari"
			set this_link to do JavaScript "document.links[" & i & "].text" in document 1
			if this_link is link then
				return (do JavaScript "document.links[" & i & "].href" in document 1)
				exit repeat
			end if
		end tell
	end repeat
	return f
end find_link

on page_loaded(timeout_value)
	delay 2
	repeat with i from 1 to the timeout_value
		tell application "Safari"
			if (do JavaScript "document.readyState" in document 1) is "complete" then
				return true
			else if i is the timeout_value then
				return false
				delay 1
			end if
		end tell
	end repeat
	return false
end page_loaded

PS: does the mail script work?

You can also use curl to download the HTML of the page, find the link address by searching on the link text and then open it. I don’t have Real Player installed, so can’t test my approach (not shown) or Stephan’s, but Stephan’s certainly goes to the right page for me, downloads the video and is much more efficient in getting there.

Indeed Adam, this can be even done with an one-liner

open location (do shell script "curl http://democracynow.org/streampage.pl | grep video | cut -f 4 -d '\"'")

Very efficient, Stefan. :cool:

What app is supposed to open those files? Quicktime won’t, and it defaults to Smile, of all things.

Real Player