Error connecting to url

I am new to Applescript. My programming experience is limited to VBA / Excel.

I have a subscription to Factiva that gives me access to various newspapers/magaazines. From the Factiva webpage, I can choose the country of the publication (usually UK), pick the name and date of the poublication (for instance the latest edition of The Economist) and click on a link to access individual articles.

I would like to use Applescript to automate this process, if possible. The steps would be as follows:

  • prompt me to choose a publication (let’s say The Economist),
  • find the latest publication,
  • download automatically all the articles in that edition and finally
  • combine and format the articles in a single Word document.

So far, I managed to tell Safari to open the starting page of Factiva’s website.
tell application “Safari”
make new document at end of documents
set the URL of document 1 to “ sid=xxxxxxxx”
end tell

note: I hid the part after “side=” as I assume it contains my login & password information.

The next page shows by default a list of US publications. I switch to UK publications by choosing “United Kingdom” from the drop-down list at the top-left corner of the screen. The resulting url is:
Factiva”, where 1811821 is the code for “United Kingdom”.

Therefore, I changed my script to directly access the url above:
tell application “Safari”
make new document at end of documents
set the URL of document 1 to “Factiva
end tell

Unfortunately, I get an error message: “Server error in ‘/’ Application”. Why?

Model: iMac Core Duo
AppleScript: AppleScript 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hi Caezar

you can use this command to open a webpage without using safari.

property target_URL : "    sid=xxxxxxxx"
open location target_URL

i think! (but aren’t sure) that you may have to incorparate some system events scripting to hit popup menus etc. in a safari browser window
try the open location command anyhow see what results you get.
you will need to fill in the correct url!


Presumably you have to log in before Factiva’s server will let you access any of the other pages. Without being subscribed to the site, it’s difficult to suggest a script solution, but perhaps this might give you somewhere to start your own experiments:

tell application "Safari"
	make new document at end of documents
	set the URL of document 1 to "" -- Your login details here.
	set maxDelay to minutes -- Allow 1 minute (say) for the initial page to load.
	set delayInterval to 2 -- . checking every two seconds.
	-- Wait for the initial page to finish loading or until the scripted delay times out.
	set delaySoFar to 0
	repeat until ((do JavaScript "document.readyState" in document 1) is "complete")
		delay delayInterval
		set delaySoFar to delaySoFar + delayInterval
		-- If the initial page hasn't completed within the allotted time, show a message and stop the script.
		if (delaySoFar > maxDelay) then
			display dialog "This script has given up waiting for the initial page to load."
			error number -128
		end if
	end repeat
	-- If the script hasn't stopped, change the URL of the front document to the UK page.
	set the URL of document 1 to ""
end tell

Thanks to you both. The scripts you sent me do work for the starting Factiva web page, but they still do not work for the second page (the one that goes directly to UK publications).

I tried to view the HMTL code of the first page, but it is like Hebrew to me. Even without any knowledge of HTML, I assume the part of the code that deals with choosing the type of publication (including UK’s publications) is that below:

Top Business News
Top World News
United Kingdom
United States

How can I tell Safari to toggle between option values? Is it through a do JavaScript statement in AppleScript?