D
D
Dmitry Sopot2017-01-22 17:49:32
ruby
Dmitry Sopot, 2017-01-22 17:49:32

Parser in Ruby?

Guys need help. I wrote a parser on the site, but it collects data from one page, how to make it go to another page and collect data further? I can show the script code

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Ivanov, 2017-01-22
@Fly3110

Parse links in the code and add them to the job queue for subsequent parsing.

A
Anton Melnik, 2017-02-03
@pixelgoo

For not very complex parsing, open-uri and nokogiri are enough.
In a loop, you sort through your array with the necessary pages and save all the links.

array_of_pages.each_with_index do |page_for_parsing, index|
  urls[index] = "http://www.site.com/#{page_for_parsing}"
end

Then you sort through the links and pull out the necessary information with the help of nokogiri.
urls.each_with_index do |url_for_parsing, index|
  page = open urls[index]
  doc = Nokogiri::HTML(page)
  doc.css('.class').each do |stuff|
    # Обрабатываем информацию
  end

If you need something more complicated, then the mechanize gem. There is a small good series of articles on Ruby parsing on Habré.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question