通过网页搜索

编程入门 行业动态 更新时间:2024-10-24 06:35:12
本文介绍了通过网页搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

嘿,我正在研究一个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'

更多推荐

通过网页搜索

本文发布于:2023-10-26 12:01:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1530078.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网页搜索

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!