Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Beautiful Soup: get text from element

I am looping through elements of type <td> but am struggling to extract the <td> text.

HTML:

<td class="cell">
 Brand Name 1
 <br/>
 (
 <a class="tip" title="This title">
  Authorised Resellers
 </a>
 )
</td>

: Desired output:

Brand name: Brand name 1
Brand distribution type: Authorised Reseller

I have tried:

for brand in brand_loop:
  print(brand.text)

But this does not print the text following the opening <td> tag ("Brand Name 1").

Any suggestions? Thanks!

like image 991
Robert Beviss-Challinor Avatar asked Jan 18 '26 06:01

Robert Beviss-Challinor


1 Answers

Try

for brand in brand_loop:
  print(brand.text)
  print(brand.find('a').text)

You can only print the text of the selected element directly.

like image 63
soumith Avatar answered Jan 19 '26 18:01

soumith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!