Live data from Hacker News

Ask HN: I want to scrape a web page...

news.ycombinator.com

11–18 of 18 posts

Re: Ask HN: I want to scrape a web page...

#11
Most every option is documented here: http://stackoverflow.com/questions/2861/options-for-html-scr...

You'll likely find this tool handy once you choose your framework: http://www.selectorgadget.com/

Another quick and dirty way: http://googlemapsmania.blogspot.com/2008/10/data-scaping-wik...

Re: Ask HN: I want to scrape a web page...

#12
post #10

Earlier quoted context omitted.

I've never written anything like this... Is there a function like CURL that downloads the page as a string from a URL?

require 'net/http' require 'uri' output = Net::HTTP.get(URI.parse("http://www.google.com"))

curb is a lot faster than net/http

require 'curb' c = Curl::Easy.perform("http://www.google.com) puts c.body_str

Re: Ask HN: I want to scrape a web page...

#13
I recently did something similar using anemone to crawl the website, and Hpricot to scrape each individual web page and add to the database.

Anemone is great because it can focus your crawl to only url's that match a certain pattern, which really helps you traverse a small portion of a larger website (like a University site). You can also do specific actions on pages that match a certain pattern.

For scraping, anemone natively supports nokogiri, so since you're coming from a blank slate, it might be easiest to learn nokogiri. Before discovering anemone, I had already written what needed to be done on each page in hpricot, so my code is a bit messy, but it's not that difficult to get anemone and hpricot to work together.

Re: Ask HN: I want to scrape a web page...

#14
I see people are saying use Hpricot or Nokogiri and you have gone on to choose Hpricot. Not a good choice. Hpricot was the work of the hacker _why who has now disappeared. But even before he disappeared nokogiri overtook hpricot in performance. He even tweeted "caller asks, “should i use hpricot or nokogiri?” if you're NOT me: use nokogiri. and if you're me: well cut it out, stop being me".

So please, use nokogiri it's a great library and the only thing I really miss from ruby-land in python.

Re: Ask HN: I want to scrape a web page...

#15
post #10

Earlier quoted context omitted.

require 'net/http' require 'uri' output = Net::HTTP.get(URI.parse("http://www.google.com"))

curb is a lot faster than net/http require 'curb' c = Curl::Easy.perform(" http://www.google.com ) puts c.body_str

Premature optimization much?

Re: Ask HN: I want to scrape a web page...

#16
post #10

Earlier quoted context omitted.

require 'net/http' require 'uri' output = Net::HTTP.get(URI.parse("http://www.google.com"))

curb is a lot faster than net/http require 'curb' c = Curl::Easy.perform(" http://www.google.com ) puts c.body_str

So apparently accessing a secure URL isn't straightforward... No login is required, its just an HTTPS but it won't go in curb.

Re: Ask HN: I want to scrape a web page...

#17

Earlier quoted context omitted.

curb is a lot faster than net/http require 'curb' c = Curl::Easy.perform(" http://www.google.com ) puts c.body_str

So apparently accessing a secure URL isn't straightforward... No login is required, its just an HTTPS but it won't go in curb.

Wasn't an SSL problem but a cookie problem...

Re: Ask HN: I want to scrape a web page...

#18
post #10

Earlier quoted context omitted.

require 'net/http' require 'uri' output = Net::HTTP.get(URI.parse("http://www.google.com"))

curb is a lot faster than net/http require 'curb' c = Curl::Easy.perform(" http://www.google.com ) puts c.body_str

I wanted to thank you for your help. I wrote a script to scrape over 30,000 courses and textbooks from Arizona State University successfully in a couple days.
Post reply on HN