How to use XPath to get certain Html elements from a webpage

时间:2019-04-23 15:16:16

标签: java javafx xpath web-scraping

I am building a web-scraper using Java and Javafx, where I am using getbyXPath to get Html elements. As shown in the Image of Html source code for the webpage, I want to get the <td> elements containted in each <th> element.

This is a part of my code I'm using:

...
List<?> t = (List<?>) e.getByXPath(".//th");
for (HtmlElement et : (List<HtmlElement>)t) {
    if (et.asText().equals("ATTRIBUTES")) {
         HtmlElement td = (HtmlElement) et.getFirstByXPath(".//td");
...

However, with this code, I get null as the value in td. What am I doing wrong?

0 个答案:

没有答案