I have this html code: code html
I just want "a" tag contained in "td" tag.
I tried this:
Elements tables = body.getElementsByTag("table");
for (Element table : tables) {
if (table.className().toLowerCase().contains("infobox")) {
Elements link=table.getElementsByTag("a");
for(Element el:link)
System.out.println(el.text());
break;
}
}
but it extracts the tag "a" of "th" and "td" while I just want the tag "a" of "td". Thank you.
EDIT I solved this way:
Elements tables = body.getElementsByTag("table");
for (Element table : tables) {
if (table.className().toLowerCase().contains("infobox")) {
Elements t1 = table.select("td");
Elements t2 = t1.select("a");
for(Element el:t2)
System.out.println(el.text());
break;
}
}
Or simple you can do
for(Element e : doc.select("table.infobox td a")){
System.out.println(e.text());
}
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.