tags:

views:

41

answers:

2

How do you search the Web Page Source in ruby Hard to explain, but heres a the code for doing it in Python

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

A quick look at Google gave me this: http://snippets.dzone.com/posts/show/2430

flq
+2  A: 

Directly porting your code:

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

If you want to do things like follow redirects, you'll want to read the documentation.

Jim Puls