我有這段代碼,它給了我任何谷歌搜索條目的搜索結果的標題。不過我想鏈接「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)
更多的信息來幫助你。請參閱此鏈接:https://stackoverflow.com/help/how-to-ask – Radio