gpt4 book ai didi

java - 确定 URL 是否为 Feed

转载 作者:行者123 更新时间:2023-12-02 07:23:14 25 4
gpt4 key购买 nike

Possible Duplicate:
How To Discover RSS Feeds for a given URL

给定一个 URL,我想知道它是否是 Feed。

Zend Framework ,可以将 URL 导入为 feed :

try {
$slashdotRss =
Zend_Feed::import('http://rss.slashdot.org/Slashdot/slashdot');
} catch (Zend_Feed_Exception $e) {
// feed import failed
echo "Exception caught importing feed: {$e->getMessage()}\n";
exit;
}

如果抛出异常,那么我就知道该 URL 不是 feed。

我想在 Java 中做同样的算法,所以我的问题是:Zend 如何知道 URL 是否是 feed ?

最佳答案

我要做的就是将其设置为 rome并尝试解析它。如果解析失败,会抛出FeedException:

public boolean tryFeed(String feedUrl) throws IOException,MalformedURLException { 
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = null;
try {
feed = input.build(new XmlReader(new URL(feedUrl)));
return true;
} catch (FeedException e) {
// Feed's invalid
return false;
}

}

关于java - 确定 URL 是否为 Feed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13920346/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com