Using Nokogiri to scrape groupon deal
Posted
by
hyngyn
on Stack Overflow
See other posts from Stack Overflow
or by hyngyn
Published on 2012-03-19T23:21:15Z
Indexed on
2012/03/19
23:29 UTC
Read the original article
Hit count: 205
I'm following the Nokogiri railscast to write a scraper for Groupon. I keep on getting the following error when I run my rb file.
traveldeal_scrape.rb:10: warning: regular expression has ']' without escape: /\[0-9
\.]+/
Flamingo Conference Resort and Spa Deal of the Day | Groupon Napa / Sonoma
traveldeal_scrape.rb:9:in `block in <main>': undefined local variable or method
`item' for main:Object (NameError)
Here is my scrape file.
require 'rubygems'
require 'nokogiri'
require 'open-uri'
url = "http://www.groupon.com/deals/ga-flamingo-conferences-resort-spa?c=all&p=0"
doc = Nokogiri::HTML(open(url))
puts doc.at_css("title").text
doc.css(".deal").each do |deal|
title = deal.at_css("#content//a").text
price = deal.at_css("#amount").text[/\[0-9\.]+/]
puts "#{title} - #{price}"
puts deal.at_css(".deal")[:href]
end
I used the exact same rubular expression as the tutorial. I am also unsure of whether or not my CSS tags are correct. Thanks!
© Stack Overflow or respective owner