我试图从几个网站获取价格,但我无法这样做。例如,现在我正在尝试从 snapdeal 中获取价格,但我失败了
module HomesHelper
require 'mechanize'
require 'nokogiri'
def scrape
mechanize=Mechanize.new
page = mechanize.get('http://www.snapdeal.com/product/apple-iphone-6-16-gb/1270529654')
doc=page.parser
price= doc.css("div #buyPriceBox span .payBlkBig selectorgadget_selected").text
puts price
end
end
最佳答案
尝试以下抓取语句。希望这对你有用
doc.css("div #buyPriceBox .pdp-e-i-PAY div.pdp-e-i-PAY-r span span.payBlkBig").text
关于ruby-on-rails - Rails 使用 nokogiri 和 Mechanize 获取价格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33991525/