【发布时间】:2022-11-28 01:10:34
【问题描述】:
<td class="right" data-stat="players_used">23</td>
试图通过 BeautifulSoup 提取字符串“players_used”。
目前,我能够从此标签中提取内容,但我不知道如何通过 BeautifulSoup 提取字符串“players_used”。有人可以看看这个吗?
【问题讨论】:
标签: web-scraping beautifulsoup
<td class="right" data-stat="players_used">23</td>
试图通过 BeautifulSoup 提取字符串“players_used”。
目前,我能够从此标签中提取内容,但我不知道如何通过 BeautifulSoup 提取字符串“players_used”。有人可以看看这个吗?
【问题讨论】:
标签: web-scraping beautifulsoup
只需使用.get() 来提取属性值:
from bs4 import BeautifulSoup
soup = BeautifulSoup('<td class="right" data-stat="players_used">23</td>')
soup.find('td').get('data-stat')
【讨论】: