I don’t need to crawl the whole internet, I just need to open a few URL, extract other URL, and then save some page in a way that they can be browsed on the disk later. What library would be appropriate to program that?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Mechanize is very good for those sort of things.
http://mechanize.rubyforge.org/mechanize/
In particular this page will help:
http://mechanize.rubyforge.org/mechanize/GUIDE_rdoc.html
Under the covers Mechanize uses Nokogiri to parse the document. Here’s a simple version using Open-URI and Nokogiri to read a page, extract all links and write the HTML.
Added example:
Accessing the links is easy. This uses CSS accessors:
This uses XPath to do the same thing:
Saving the content is easy. Create a file, and ask Nokogiri to spit it out as HTML: