HELP PLEASE - Automating safari link clicks

I am trying to download a lot of information from a dynamically created web page. I want a script to click on links on the page to open a new page and then copy the info on that page and save it to an excel file. Then click another link on the page we just opened, copy all the info, paste to excel then close both windows and go back to the main window and start over. Each page has 20 links (about) and there are 30 pages of links.

When I copy the link I need to click here is what I get:
http://www.privateequityinfo.com/searchhedge.php?type=1&stype=1&firmname=&state[]=AL&employeesNo=&op=<&q=&op1=<&q1=&x=20&y=17#

It is a password protected site (I am a member). So the link does not help in and of itself - I have to ACTUALLY click it. I can copy and paste using system events but the clicking has really got me stumped. When you do a mouse over the link bar on the bottom says: “go to page #”.

Any and all help appreciated!

Hi,

try this to login, there is also included a routine to find links with javascript

set site_url to "http://www.privateequityinfo.com/login.php"
set link_text to "Login"
tell application "Safari"
	activate
	open location site_url
	-- wait until page loaded
	if my page_loaded(20) is false then return
	-- get number of links
	set f to my find_link(link_text)
	if f is false then -- link text not found
		display dialog "Link \"" & link_text & "\" not found."
	else
		-- get the url and open the link url
		set link_url to do JavaScript "document.links[" & f & "].href" in document 1
		open location link_url -- opens in new page
		tell application "System Events" to tell process "Safari"
			keystroke tab
			keystroke "username"
			keystroke tab
			keystroke "password"
			keystroke return
		end tell
	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" to set this_link to do JavaScript "document.links[" & i & "].text" in document 1
		if this_link is link then
			set f to this_link
			exit repeat
		end if
	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
			else
				delay 1
			end if
		end tell
	end repeat
	return false
end page_loaded

Thanks for the help, unfortunately it did not work. Here is the actual HTML:

Abbott Capital Management LLC New York New York $5,586

That appears to be the place I need to click. What should I put in top seatch for? Nothing comes up. Also, on the next page I cannot even view any source. Help appreciated!

Thanks.