4 ruby google-search google-search-api
假设我拥有Google搜索结果页面的完整HTML.有没有人知道任何现有的代码(Ruby?)来搜索/解析Google搜索结果的第一页?理想情况下,它可以处理可以在任何地方出现的购物结果和视频结果部分.
如果没有,一般来说,最好的基于Ruby的屏幕抓取工具是什么?
澄清:我知道以编程方式/ API方式获取Google搜索结果很困难/不可能而且简单地说CURLing结果页面存在很多问题.这里有关于stackoverflow的这两点的共识.我的问题不同.
khe*_*lll 10
这应该是非常简单的事情,看看由Ryan Bates施放的ScrAPI屏幕的屏幕刮痧.你仍然可以做到没有抓住 libs,只是坚持像nokogiri这样的简单事情.
更新:
来自nokogiri的文档:
require 'nokogiri'
require 'open-uri'
# Get a Nokogiri::HTML:Document for the page we’re interested in...
doc = Nokogiri::HTML(open('http://www.google.com/search?q=tenderlove'))
# Do funky things with it using Nokogiri::XML::Node methods...
####
# Search for nodes by css
doc.css('h3.r a.l').each do |link|
puts link.content
end
####
# Search for nodes by xpath
doc.xpath('//h3/a[@class="l"]').each do |link|
puts link.content
end
####
# Or mix and match.
doc.search('h3.r a.l', '//h3/a[@class="l"]').each do |link|
puts link.content
end
Run Code Online (Sandbox Code Playgroud)