user7574473
user7574473

Reputation:

How to get text from a <td> using BeautifulSoup?

I try to get the text from an html looking like this:

</td><td align='center'>&nbsp;</td><td align='right'>0.1200</td><td align='left'><img

I'm interested in getting the number "0.1200".

My code is this:

`url = "http://...."
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, "lxml")
for link in soup.findAll('td', {'align': 'right'}):
    for row in link.find_next_sibling("td"):
        print(row)

I get an error message "TypeError: 'NoneType' object is not iterable". Any sugestions on fixing the problem?

Upvotes: 1

Views: 5183

Answers (1)

Ali
Ali

Reputation: 1357

Can you try this out please? (It is hard to help you out if you don't give us the URL)

Code:

soup = BeautifulSoup(plain_text, "lxml")
for link in soup.findAll('td', {'align': 'right'}):
    print(link.text)

Upvotes: 1

Related Questions