1
I’m trying to get specific values within a table, I have a similar code that I already use in the same way in another unique table structure within html, the problem and that I can’t get the text of the field, within that structure with a table inside the other.
Below the table structure and the value I want to pick up and what I’ve been trying to do:
<table id="principal">
<tr>
<td id="TB01">
<table class="secondary"></table>
</td>
<td id="TB02">
<table class="secondary"></table>
</td>
<td id="TB03">
<table class="secondary">
<tr></tr>
<tr>
<td></td>
<td></td>
<td>ESSE VALOR -> R$5.388,50</td>
</tr>
</table>
</td>
<td id="TB04">
<table class="secondary"></table>
</td>
</tr>
</table>
Code I’ve been trying to use:
import requests
from bs4 import BeautifulSoup
url = "http://www.bmf.com.br/bmfbovespa/pages/lumis/lum-boletim-online-new-ptBR.asp?Acao=BUSCA&cboMercadoria=DOL"
resp = requests.get(url)
bs = BeautifulSoup(resp.text, "html.parser")
trs = (
bs.find("td", {"id": "TB03"})
.find("table", {"class": "secondary"})
.findAll("tr")
)
for tr in trs:
if trs.index(tr) == 2:
tds = tr.findAll("td")
for td in tds:
if tds.index(td) == 3:
valor = td.get_text()
print(valor)
Can anyone help me in how I can return the specific value, always returns None when I print, or this Attributeerror error: 'Nonetype' Object has no attribute 'find'.
If any of the answers solved your problem, mark it as correct. If not, comment asking for further clarification.
– yoyo