Patrick Balada
Patrick Balada

Reputation: 1450

How can I extract the name of a <tr> tag by using Beautiful Soup?

Given the following html document, how can I extract the string "CLN8"?

<tr data-table-chart-alt-symbol="CLN8" data-table-chart-symbol="@CL.1">
<td class="first text" data-field="symbol"><a href="//www.cnbc.com/quotes/?symbol=%40CL.1">OIL</a></td>
<td data-field="last"></td>
<td class="arrow" data-field="change_arrow"><div class="icon unch">---</div></td>
<td data-field="change"></td>
<td data-field="change_pct"></td>
<td data-field="volume"></td>
</tr>

Upvotes: 0

Views: 27

Answers (1)

Ajax1234
Ajax1234

Reputation: 71451

You can use BeautifulSoup.find:

from bs4 import BeautifulSoup as soup
d = soup(html, 'html.parser').find('tr')['data-table-chart-alt-symbol']

Output:

'CLN8'

Upvotes: 1

Related Questions