从谷歌搜索结果中获取链接

问题描述:

我有这段代码,它给了我任何谷歌搜索条目的搜索结果的标题。不过我想链接“href”标签标签。示例代码是需要从谷歌搜索结果中获取链接

<h3 class="r"><a href="https://www.lonelyplanet.com/india" onmousedown="return rwt(this,'','','','1','AFQjCNG5Z2TycA5Rni1X_vKY3Gt9BEVS4w','','0ahUKEwi-99jMpqXWAhUKO48KHdfqBcIQtwIIJzAA','','',event)" target="_blank">Lonely Planet India - India - Lonely Planet</a></h3> 



require 'mechanize' 
agent = Mechanize.new 
page = agent.get("https://www.google.com/videohp") 
search_form = page.form('f') 
search_form.q = 'india' 
page = agent.submit(search_form) 
puts page.search('h3.r').map(&:text) 
+0

更多的信息来帮助你。请参阅此链接:https://stackoverflow.com/help/how-to-ask – Radio

page.search('h3.r a').map{|a| a['href']} 
+0

这不提供问题的答案。要批评或要求作者澄清,请在其帖子下方留言。 - [来自评论](/ review/low-quality-posts/17349827) –

+0

这是正确的解决方案。 – pguardiario