开发者

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开发者_StackOverflow社区 found"


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).


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)


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'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜