getting text from Safari and clicking links

Hi,

There’s a subscription website I read that I’d like to archive. I’m trying to make the process as easy as possible. The page is your normal web page, lots of headers, links, toolbars. I’m able to get just the text by doing lots of set tsaid’s.


tell application "Safari"
	if name of document of window 1 contains "WebSite" then
		try
			set safariText to text of document of window 1
			tell me to set text item delimiters to {"text that occurs before the main content"}
			set webFrame to text items of safariText		
			set newString to my processText(item 1 of webFrame as text)
			set the clipboard to newString
		end try
	end if
end tell

on processText(myString)
	set text item delimiters to {"Page Number:"}
	set myString to text item 1 of myString
	set text item delimiters to {"part of the footer of the page"}
	set myString to text item 1 of myString as string
	set text item delimiters to {" **  return return some text return  ** ")
	set myString to text item 2 of myString as string
	return myString
end processText

It seems like that’s the fastest way to parse a long paragraph. Set text item delimiters to some long string that can act as a delimiter.

At one point, I’m trying to set the tsaid to return return text return. It seems to not be “\n\ntext\n”, as that enters the real returns in the script. “\n\ntext\n” isn’t it either.

I’m also trying to click some links on the page for previous and next page. I can’t set the browser url to something else since the link contains a javascript onClick and another dom action. They differ slightly per page. Maybe I can by simulating all those actions. Are there some docs about applescript and controlling Safari? It’d be nice to be able to get a list of links, find the correct one, and click it.

Thanks for any help.

Gary