Python crawling: When deleting tr elements on the first page, they are also deleted on other pages.

Asked 2 years ago, Updated 2 years ago, 51 views

Hello.

There are pages 1 to 3, and only the first tr element is erased in the image above page 1 I want to import data, but if I erase it with deltr[0], tr[0] on page 2 and 3 will also be deleted. How can we solve this??

python crawling

2022-09-21 11:46

1 Answers

If it's simply tr[0], all the first <tr> will be targeted, so you should set a value that can be identified by an id or user-defined attribute in the tag and select only that tag to erase it.

For example:

<table id="firstMan">
    <tr data-idx="1">
        <td id="removeMe"></td>
        <td></td>
    </tr>
    <tr data-idx="2">
        <td id="dontShoot"></td>
        <td></td>
    </tr>
</table>
<table id="secondary">
    <tr data-idx="1">
        <td></td>
        <td></td>
    </tr>
    <tr data-idx="2">
        <td>
        <td></td>
    </tr>
</table>

You must have an identifier that distinguishes you from other tags in this way to clear only the tags you want.


2022-09-21 11:46

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.