Jsoup 解析 RSS 时出现错误?
我正在尝试从此提要获取文章链接列表:
http://rss.cbc .ca/lineup/topstories.xml
但是,当 Jsoup 读入它时,标签中的链接http://www.cbc.ca/news/?cmp=rss
变为 http://www.cbc.ca /news/?cmp=rss
即标签自行关闭,如果我这样做,
Elements items = doc.select("link");
它不会抓取任何链接。
I'm trying to grab a list of links to articles from this feed:
http://rss.cbc.ca/lineup/topstories.xml
However, when Jsoup reads it in, the links in the tags <link>http://www.cbc.ca/news/?cmp=rss</link>
become <link />http://www.cbc.ca/news/?cmp=rss
Ie the tag self closes and if I do
Elements items = doc.select("link");
it doesn't grab any of the links.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JSoup 是一个 HTML 解析器,在 HTML 中,
link
元素被定义为具有空的内容模型。您提供的 url 似乎包含有效的 xml,所以为什么不尝试实际的 xml 解析器或提要解析器库,例如 罗马?编辑:要使用 JDK 的 Xpath 实现从文件中提取链接,您可以使用如下代码:
JSoup is a HTML parser, in HTML the
link
element is defined to have an empty content model. The url you gave seems to contain valid xml, so why don't you try an actual xml parser or a feed parser library like rome?Edit: To extract links from the file using JDK's Xpath implementation you can use code like the following: