Rails 4
我正在尝试实施一种从Google购物搜索中提取定价信息的简单方法:https://www.google.com/search?q=arc%27teryx+beta+ar+pant&ie=utf-8&oe=utf-8#q=arc%27teryx+beta+ar+pant&tbs=vw:l&tbm=shop
在使用Nokogiri和SelectorGadget的RailsCast之后,我很容易在walmart.com页面上实现这一点。当我改变这个以从谷歌购物中提取结果时,我得不到任何结果。我的@ doc.css空白了。
控制器:
def index
url = "https://www.google.com/search?q=arc%27teryx+beta+ar+pant&ie=utf-8&oe=utf-8#q=arc%27teryx+beta+ar+pant&tbs=vw:l&tbm=shop"
@doc = Nokogiri::HTML(open(url))
end
查看:
# ".pslmain" is the listing container provided by SelectorGadget
<% @doc.css(".pslmain").each do |item| %>
Title: <%= item.at_css(".pstl").text %><br>
Price: <%= item.at_css(".b").text[/\$[0-9\.]+/] %><br>
Link: <%= item.at_css(".pstl")[:href] %><br><br><br>
<% end %>
我哪里错了?