Reputation: 1450
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
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