使用 ROME 提取饲料内容?

发布于 2024-11-25 13:40:31 字数 1218 浏览 6 评论 0原文

如何使用 Java 中的 ROME 获取字符串形式的内容以获取某些提要。

目前这就是我得到的

String feedURL = “...”;
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));

System.out.println(feed);

for (final Iterator iter = feed.getModules().iterator(); iter.hasNext();){
    System.out.println("\t" + ((Module)iter.next()).getUri());
}

System.out.println("Titles of the " + feed.getEntries().size() + " entries:");
for (final Iterator iter = feed.getEntries().iterator(); iter.hasNext();){
     System.out.println("\t" + ((SyndEntry)iter.next()).getContents());
}

然后它的输出是:

SyndContentImpl.interface=interface com.sun.syndication.feed.synd.SyndContent
SyndContentImpl.type=html
SyndContentImpl.mode=null

    SyndContentImpl.value=          <p><a href="http://www.flickr.com/people/64539367@N07/">MiscDot</a> posted a photo:</p>

<p><a href="http://www.flickr.com/photos/64539367@N07/5954881384/" title="03a"><img src="http://farm7.static.flickr.com/6024/5954881384_5390838321_m.jpg" width="240" height="240" alt="03a" /></a></p>

但我想要的只是获取内容的字符串: SyndContentsImpl.value

How do I get the contents as a String using ROME in Java for some feed.

At the moment this is what I got

String feedURL = “...”;
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));

System.out.println(feed);

for (final Iterator iter = feed.getModules().iterator(); iter.hasNext();){
    System.out.println("\t" + ((Module)iter.next()).getUri());
}

System.out.println("Titles of the " + feed.getEntries().size() + " entries:");
for (final Iterator iter = feed.getEntries().iterator(); iter.hasNext();){
     System.out.println("\t" + ((SyndEntry)iter.next()).getContents());
}

Then the output of this is:

SyndContentImpl.interface=interface com.sun.syndication.feed.synd.SyndContent
SyndContentImpl.type=html
SyndContentImpl.mode=null

    SyndContentImpl.value=          <p><a href="http://www.flickr.com/people/64539367@N07/">MiscDot</a> posted a photo:</p>

<p><a href="http://www.flickr.com/photos/64539367@N07/5954881384/" title="03a"><img src="http://farm7.static.flickr.com/6024/5954881384_5390838321_m.jpg" width="240" height="240" alt="03a" /></a></p>

But what I want is to just get the string of the contents:
SyndContentsImpl.value

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

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

发布评论

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

评论(1

权谋诡计 2024-12-02 13:40:31

像...

for (Iterator<?> entryIter = syndFeed.getEntries().iterator(); entryIter.hasNext();) {
    SyndEntry syndEntry = (SyndEntry) entryIter.next();

    if (syndEntry.getContents() != null) {
        for (Iterator<?> it = syndEntry.getContents().iterator(); it.hasNext();) {
            SyndContent syndContent = it.next();

            if (syndContent != null) {
                String value = syndContent.getValue();
            }
        }
    }
}

Something like...

for (Iterator<?> entryIter = syndFeed.getEntries().iterator(); entryIter.hasNext();) {
    SyndEntry syndEntry = (SyndEntry) entryIter.next();

    if (syndEntry.getContents() != null) {
        for (Iterator<?> it = syndEntry.getContents().iterator(); it.hasNext();) {
            SyndContent syndContent = it.next();

            if (syndContent != null) {
                String value = syndContent.getValue();
            }
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文