0

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?

user13
  • 1
  • 3
  • 1
    `th` elements don't contain `td` elements... They are siblings – Alejandro Apr 23 '19 at 16:45
  • Also on chrome if you right click and inspect the element you can right click the element and copy the xpath(From inspection view) saving headaches from trying to build them Edit:I just realized your trying to iterate through a list programmatically so nvm but useful for double checking link to explanation https://stackoverflow.com/a/42194160/8359107 – Matt Apr 23 '19 at 19:42

0 Answers0