I want to know if its possible to me get, using beautiful soup, a few lines up of html line:
<tr id="12590559" class="">
<td>
<span class="he16-1 tip-top" title="Cracker"></span>
</td>
<td>
cracker.crc
</td>
In that example I want to extract the id but with the tittle information using:
soup = BeautifulSoup(lista.content, "lxml")
id = soup.find(attrs={"title": "Cracker"})
I can get the
<span class="he16-1 tip-top" title="Cracker"></span>
but I want to get also the id
. Can I use the BeautifulSoup
to get a few lines up?
Use BeautifulSoup's find_parent
/find_parents
method.
pass tr
as parent search item and ['id']
will print id value
id.find_parent('tr')['id']
>> '12590559'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With