Rails 使用 nokogiri 和 mechanize 获取价格
Rails fetching price using nokogiri and mechanize
我正在尝试从多个网站获取价格,但我现在无法执行 so.For 示例 我正在尝试从 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
我正在尝试从多个网站获取价格,但我现在无法执行 so.For 示例 我正在尝试从 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