I am trying to parse HTML table using jsoup. I am new to jsoup and I have read some tutorial on it. I need to extract values from table for each column from this website: https://www.basketball-reference.com/boxscores/pbp/201905160GSW.html . I tried getting every timestamps, but it's only printing a single element. This is the code I tried last.
Document doc = Jsoup.connect("https://www.basketball-reference.com/boxscores/pbp/201905160GSW.html").get();
Elements trs = doc.select("table");
for(Element tr : trs) {
Elements tds = tr.getElementsByTag("td");
Element td = tds.get(0);
System.out.println(td.text());
}
Do you understand your code?
It selects all tables and puts them into trs
variable:
Elements trs = doc.select("table");
Then it iterates over each table:
for(Element tr : trs) {
From each table it selects all cells 'td':
Elements tds = tr.getElementsByTag("td");
then it takes only the first cell
Element td = tds.get(0);
and prints its contents
System.out.println(td.text());
Some of these actions are not necessary but now with that explanation you should have a good start.
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.