【发布时间】:2014-12-10 11:53:31
【问题描述】:
我遇到了 Java 网页抓取问题。这是网站:(http://www.bbc.com/sport/football/teams/liverpool)
我想从这里抓取标题数据。
注意:我正在使用 Jaunt 库。
public class News extends JFrame
{
private String title;
private JLabel labelText2;
News()
{
setSize(800, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
labelText2 = new JLabel();
setLayout(null);
labelText2.setBounds(10, 10, 550, 20);
add(labelText2);
}
public void Club_News()
{
try {
UserAgent userAgent = new UserAgent();
userAgent.visit("http://www.bbc.com/sport/football/teams/liverpool");
String div = userAgent.doc.findFirst(
"<div id=\"more-headlines\" class=\"mod mod-separator\">").innerHTML();
labelText2.setText("Latest News Headlines: " + div);
} catch (JauntException e) {
System.err.println(e);
}
}
}
【问题讨论】:
-
需要包括确切问题的详细信息 - 还可以使用一些拼写检查和正确使用代码格式。
-
仅供参考 - 您可以在 findFirst 方法的搜索查询中使用撇号而不是转义引号。
标签: java web-scraping jaunt-api