I'm facing a problem with Java web scraping. This is the website: (http://www.bbc.com/sport/football/teams/liverpool)
From here I want to scrape the Headlines data.
Note: I'm using Jaunt Library.
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);
}
}
}
You need to call your
Club_News()
method. You can make it the last statement in your constructor:To make errors obvious, add a line to your
catch
block at the end ofClub_News()
: