I search links via css form page = agent.get('http://www.print-index.ru/default.aspx?p=81&gr=198')
and after that I have in page variable a lot of links but I don't know how use them, how click on them via Mechanize. I found on stackoverflow this method:
page = agent.get "http://google.com"
node = page.search ".//p[@class='posted']"
Mechanize::Page::Link.new(node, agent, page).click
but it works for only one link so how can I use this method for many links.
If I should post additional information, please say it.
If your goal is simply to make it to the next page and then scrape some info off of it, then all you really care about are:
The way you get to the page content could be done by using
Mechanize
OR something else, likeOpenURI
(which is part of Ruby standard lib). As a side note,Mechanize
uses Nokogiri behind the scenes; when you start to dig into elements on the parsed page you will see they come back as Nokogiri related objects.Anyways, if this were my project I'd probably go the route of using
OpenURI
to get at the page's content and thenNokogiri
to search it. I like the idea of using a Ruby standard library instead of requiring an additional dependency.Here is an example using
OpenURI
:Here's an example using
Mechanize
to get the page content (they are very similar):PS I used google to translate Russian to english.. if the variable names are incorrect, i'm sorry! :X