如何编写 python 脚本来搜索网站 html 中的匹配链接
我对 python 不太熟悉,必须编写一个脚本来执行许多功能。 基本上我仍然需要的模块是如何检查网站代码以匹配预先提供的链接。
I am not too familiar with python and have to write a script to perform a host of functions.
Basically the module i still need is how to check a website code for matching links provided beforehand.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
匹配链接是什么?他们的 HREF 属性?链接显示文字?
也许是这样的:
这将获取
somesite.com
的 HTML 内容,然后使用 BeautifulSoup 解析它,仅查找 HREF 属性以“test”开头的链接。然后它会构建这些链接的列表并将其打印出来。您可以使用文档对其进行修改以执行任何操作。
Matching links what? Their HREF attribute? The link display text?
Perhaps something like:
That will grab the HTML content of
somesite.com
and then parse it using BeautifulSoup, looking only for links whose HREF attribute starts with "test". It then builds a list of these links and prints them out.You can modify this to do anything using the documentation.
通常,您使用 urllib,urllib2(htmllib 等)用于在 Python 中进行 Web 编程。您还可以使用mechanize,curl 等。然后,为了处理 HTML 并获取链接,您需要使用像 BeautifulSoup。
Generally, you use urllib, urllib2 (htmllib etc) for programming web in Python. you could also use mechanize, curl etc. Then for processing HTML and getting links, you would want to use parsers like BeautifulSoup.
尝试 scrapy,最全面的网页提取框架。
http://scrapy.org
try scrapy , the most comprehensive web extraction framework.
http://scrapy.org