Groupon에 스크레이퍼를 작성하려면 Nokogiri railscast을 따르고 있습니다. 내 rb 파일을 실행할 때 계속 다음과 같은 오류가 발생합니다.Nokogiri를 사용하여 groupon 거래를 마칩니다.
Flamingo Conference Resort and Spa Deal of the Day | Groupon Napa/Sonoma
traveldeal_scrape.rb:9:in `block in <main>': undefined method `text' for
nil:NilClass (NoMethodError)
여기 내 스크래핑 파일입니다.
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("#content//h2/a").text
title = doc.at_css("#content//h2/a").text
price = doc.at_css("#amount").text[/[0-9\.]+/]
puts "#{title} - #{price}"
puts doc.at_css(".deal")[:href]
EDITED : 위 코드가 작동합니다!
튜토리얼과 완전히 동일한 루블 표현을 사용했습니다. 나는 또한 나의 CSS 꼬리표가 정확한지 확실하지 않다. 감사!
doc.css(".deal").each do |deal|
title = item.at_css("#content//a").text
price = item.at_css("#amount").text[/\[0-9\.]+/]
puts "#{title} - #{price}"
puts item.at_css(".deal")[:href]
end
가되어야한다 :
아마도 이미 전환했습니다. 그러나 아직 작업하고 있다면 Groupon이 훌륭한 API를 가지고 있다는 것을 알고 있습니까? https://sites.google.com/site/grouponapiv2/home –