使用 Python 从 HTML 提供 URL

发布于 2024-12-14 12:37:52 字数 104 浏览 4 评论 0原文

RSS 提要 URL 可用于站点的元数据(如果可用)。有没有办法使用 urllib2 或 HTMLParser 模块提取页面的 feed URL?或者有更好的模块可用吗?

谢谢。

The RSS feed URL is available a site's meta data (if one available). Is there a way to extract the feed URL(S) of a page using urllib2 or HTMLParser modules? Or is there a better module available?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十雾 2024-12-21 12:37:52

我更喜欢 lxml。它有一个非常好的 API,并且它的 XPath 支持使这变得相当简单:

import lxml.html
doc = lxml.html.parse(url_to_site)
feeds = doc.xpath('//link[@type="application/rss+xml"]/@href') # list feed urls

I prefer lxml. It has a very nice API, and it's XPath support makes this fairly simple to accomplish:

import lxml.html
doc = lxml.html.parse(url_to_site)
feeds = doc.xpath('//link[@type="application/rss+xml"]/@href') # list feed urls
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文