Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stumped on clicking a link with nokogiri and mechanize

perhaps im doing it wrong, or there's another more efficient way. Here is my problem:

I first, using nokogiri open an html document and use its css to traverse the document until i find the link which i need to click.

Now once i have the link, how do i use mechanize to click it? According to the documentation, the object returned by Mechanize.new either the string or a Mechanize::Page::Link object.

I cannot use string - since there could be 100's of the same link - i only want mechanize to click the link that was traversed by nokogiri.

Any idea?

like image 702
David Avatar asked Sep 20 '11 22:09

David


1 Answers

After you have found the link node you need, you can create the Mechanize::Page::Link object manually, and click it afterwards:

agent = Mechanize.new
page = agent.get "http://google.com"
node = page.search ".//p[@class='posted']"
Mechanize::Page::Link.new(node, agent, page).click
like image 122
binarycode Avatar answered Oct 27 '22 15:10

binarycode