Answer the question
In order to leave comments, you need to log in
How to parse class content from bs4 in python?
In general, there
<div class="fight-stats _enemy">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="fight-stats-table">
<tbody>
<tr valign="top">
<td width="33%" align="center" valign="top">
<div class="fight-stat" id="enemy-stat-strength">5</div>
<div class="fight-stat-icon strength"></div>
</td>
<td width="33%" align="center" valign="top">
<div class="fight-stat" id="enemy-stat-dexterity">1</div>
<div class="fight-stat-icon dexterity"></div>
</td>
<td width="33%" align="center" valign="top">
<div class="fight-stat" id="enemy-stat-critical">10</div>
<div class="fight-stat-icon critical"></div>
</td>
</tr>
</tbody>
</table>
</div>
es = 5
ed = 1
ec = 10
info = s.get('https://example/index.php?r=fights/choose&force=1&club=official', headers=headers)
soup = bs(info.content, "lxml")
es = soup.find(attrs={'class': 'fight-stat'})['enemy-stat-strength']
print("strength:", es)
Answer the question
In order to leave comments, you need to log in
Since I don't see all the html, I can suggest the following solution:
es = soup.find('div',id='enemy-stat-strength').text
ed = soup.find('div',id='enemy-stat-dexterity').text
ec = soup.find('div',id='enemy-stat-critical').text
print('strength:',es)
print('dexterity:',ed)
print('critical:',ec)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question