搜索网页内容

你如何在ruby中搜索Web页面源难以解释,但这是在Python中执行它的代码

import urllib2, re word = "How to ask" source = urllib2.urlopen("http://stackoverflow.com").read() if re.search(word,source): print "Found it "+word 

直接移植代码:

 require 'net/http' word = 'How to ask' source = Net::HTTP.get(URI.parse('http://stackoverflow.com/')) if source.match(word) puts "Found #{word}" end 

如果您想执行重定向等操作,则需要阅读文档 。