str1k3r
str1k3r

Reputation: 1519

python and search?

am looking for method and function watch i can search in web page ! ok I'll explain it : i tell my python file .. go to www.example.com and search for that world "Hello guest" and if my python file found that world "Hello guest" my python file print "the world found!" and if he don't found he print "the world not found"

Upvotes: 0

Views: 209

Answers (3)

David Ly
David Ly

Reputation: 31586

The other answers here I believe are searching the html rather than the rendered content. If that's what you want that's fine, but if you want to exclude stuff in tags then you're probably going to want to look at something that can understand html. Beautiful Soup should be able to help parse it and extract the actual text content (and a lot more)

Upvotes: 2

Marcelo Cantos
Marcelo Cantos

Reputation: 185852

Use Python's urllib module to fetch the content, and its re module to look for the word (make sure you use search instead of match; it's a common noob slip-up).

Upvotes: 2

damir
damir

Reputation: 428

if you need to match exact string, this is faster and less complicated

a = urllib.urlopen('http://www.google.com')

if 'new' in a.read():
    print 'found'
else:
    print 'not found'

Upvotes: 0

Related Questions