本文介绍了通过网页搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,我正在研究一个Python项目,该项目需要我浏览一个网页.我想浏览以查找特定的文本,如果找到了该文本,则将其打印出来.如果不是,它将打印出错误消息.我已经尝试过使用其他模块(例如libxml),但是我不知道该怎么做.
Hey I'm working on a Python project that requires I look through a webpage. I want to look through to find a specific text and if it finds the text, then it prints something out. If not, it prints out an error message. I've already tried with different modules such as libxml but I can't figure out how I would do it.
有人可以帮忙吗?
推荐答案您可以执行以下简单操作:
You could do something simple like:
import urllib2 import re html_content = urllib2.urlopen('www.domain').read() matches = re.findall('regex of string to find', html_content); if len(matches) == 0: print 'I did not find anything' else: print 'My string is in the html'更多推荐
通过网页搜索
发布评论