我使用库rome.dev.java.net来获取RSS.
代码是
URL feedUrl = new URL("http://planet.rubyonrails.ru/xml/rss");
SyndFeedInput input = new SyndFeedInput();
SyndFeed feed = input.build(new XmlReader(feedUrl));
Run Code Online (Sandbox Code Playgroud)
您可以检查http://planet.rubyonrails.ru/xml/rss是否为有效URL,并在浏览器中显示该页面.
但我从我的申请中得到例外
java.io.FileNotFoundException: http://planet.rubyonrails.ru/xml/rss
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1311)
at com.sun.syndication.io.XmlReader.<init>(XmlReader.java:237)
at com.sun.syndication.io.XmlReader.<init>(XmlReader.java:213)
at rssdaemonapp.ValidatorThread.run(ValidatorThread.java:32)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Run Code Online (Sandbox Code Playgroud)
我不使用任何代理.我在我的PC和生产服务器上遇到此异常,并且只有此URL,其他URL正在运行.
我从RSS频道抓取数据,清理它并保存在数据库中.我使用java,tidy,MySQL和JDBC.
脚步:
MySQL方案是
CREATE TABLE IF NOT EXISTS `rss_item_safe_texts` (
`id` int(10) unsigned NOT NULL,
`title` varchar(1000) NOT NULL,
`link` varchar(255) NOT NULL,
`description` mediumtext NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Run Code Online (Sandbox Code Playgroud)
JDBC连接URL是
connUrl = "jdbc:mysql://" + host + "/" + database + "?user=" + username + "&password=" + password + "&useUnicode=true&characterEncoding=UTF-8";
Run Code Online (Sandbox Code Playgroud)
Java代码是
PreparedStatement updateSafeTextSt = conn.prepareStatement("UPDATE `rss_item_safe_texts` SET `title` = ?, `link` = ?, `description` = ? WHERE `id` = ?");
updateSafeTextSt.setString(1, EscapingUtils.escapeXssInjection(title));
updateSafeTextSt.setString(2, …Run Code Online (Sandbox Code Playgroud)