简体   繁体   中英

Extracting particular table data in JSoup

I have the following HTML Code:

<tr>
    <td class="legend" data-v1="conceded" data-v2="Average</td>
    <td data-v1="29" data-v2="1.45">29</td>
    <td data-v1="14" data-v2="1.40">14</td>
    <td data-v1="15" data-v2="1.50">15</td>
</tr>

I'm trying to get the numbers '29', '14' and '15' however I don't know what their address is to select them. I can get the td with the class name using the below code:

        try {

            Document doc = Jsoup.connect(URL).get();

            Elements E = doc.select(".team-stats.line-end > tbody > tr > td.legend");
            System.out.println(E.text());

        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

However, the ones with the numbers don't have a class or ID name. How can I point to them to extract these individually.

Try this selector:

.team-stats.line-end > tbody > tr > td:not(:first-child)

Or:

.team-stats.line-end > tbody > tr > td:not(.legend)

If you want to refer to exclude the class explicitly.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM