So I'm trying to scrape some data from a WebPage, but unable to do so. I tried doing it using substring() but that's very inefficient. Here's part of the code which I've written :
Elements links;
Element link;
String url = "https://www.premierleague.com/tables";
Document document = Jsoup.connect(url).get();
links = document.select("table");
org.jsoup.nodes.Element table = document.select("table").get(0);
Elements rows = table.select("tr");
org.jsoup.nodes.Element row = rows.get(1);
Elements cols = row.select("td");
Can anyone help me by giving a few examples from the same link ?
String url = "https://www.premierleague.com/tables";
Document doc = Jsoup.connect(url).get();
Element table = doc.select("table").first();
Iterator<Element> team = table.select("td[class=team]").iterator();
Iterator<Element> rank = table.select("td[id=tooltip]").iterator();
Iterator<Element> points = table.select("td[class=points]").iterator();
System.out.println(team.next().text());
System.out.println(rank.next().text());
System.out.println(points.next().text());
output:
ChelseaCHE
1 Previous Position 1
46
Edit: to respond to your question:
System.out.println(team.next().text());
System.out.println(rank.next().text());
System.out.println(points.next().text());
team.next();
team.next();
team.next();
rank.next();
rank.next();
rank.next();
points.next();
points.next();
points.next();
System.out.println(team.next().text());
System.out.println(rank.next().text());
System.out.println(points.next().text());
output:
ChelseaCHE
1 Previous Position 1
46
Tottenham HotspurTOT
5 Previous Position 5
33
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.