Having trouble webscraping Premier League results in Java with JSoup

Viewed 37

I am a complete beginner to webscraping. I have followed a couple tutorials online, but I can't seem to get it to work with Premiere League results.

Here is the exact link I've tried scraping from: https://www.premierleague.com/results

My goal is to read all the home-team and away teams as well as get their results (1-1 etc.). If anyone could help I would really appreicate it! Below is code I've tried so far:

First attempt

String element = doc.select("div.fixtures__matches-list span.competitionLabel1").first().text();

Second attempt

Elements elements = doc.select("div.fixtures__matches-list");

Elements matches = doc.getElementsByClass("matchList");

Element ULElement = matches.get(0);

Elements childElements = ULElement.children();


for (Element e : childElements) {
    
    String first = e.select("ul.matchList").select("li.matchFixtureContainer data-home").text();
    
    System.out.println(e.text());

}

Third attempt

Elements test = doc.getElementsByClass("fixtures");

Element firstE = test.get(0);
System.out.println(firstE.text())

for (Element e : test) {
    System.out.println(e.text());
}

Fourth attempt

Elements names = doc.select("data-home");

for (Element name : names) {
    System.out.println(name.text());
}

Fifth attempt

String webUrl = "https://www.premierleague.com/results";    

Document doc = null;

try {
    doc = Jsoup.connect(webUrl).timeout(6000).get();
}
catch(IOException e) {
    e.printStackTrace();
}
    
Elements body = doc.select("div.tabbedContent");
    
for (Element e : body) {
        
String data = e.select("div.col-12 section.fixtures div.fixtures__matches-list ul.matchList").text();
        
}

I really can't figure it out.

0 Answers
Related