温馨提示:本文翻译自stackoverflow.com,查看原文请点击:python - Using BS4 to extract a attrib value
html python beautifulsoup

python - 使用BS4提取属性值

发布于 2020-03-27 11:32:02

所以我想使用bs4提取attrib的值,但无法使其正常工作。

<a href="https://store.steampowered.com/app/1046930/Dota_Underlords/?snr=1_7_7_230_150_1"  data-ds-appid="1046930" data-ds-tagids="[493,113,493,9,1708,14139,3859]" data-ds-crtrids="[4]" onmouseover="GameHover( this, event, 'global_hover', {&quot;type&quot;:&quot;app&quot;,&quot;id&quot;:1046930,&quot;v6&quot;:1} );" onmouseout="HideGameHover( this, event, 'global_hover' )" class="search_result_row ds_collapse_flag " >

多数民众赞成在相当长的标签,以便生病只是将其压缩到我需要的部分

<a href="https://store.steampowered.com/app/1046930/Dota_Underlords/?snr=1_7_7_230_150_1"  data-ds-appid="1046930"

从缩短的代码中,我需要data-ds-appid及其值,而无需知道以我的代码开头的值:

stuff = soup.find("a", {"data-ds-appid":['content']})

查看更多

查看更多

提问者
Fr06t
被浏览
56
Cobra 2019-07-03 22:57
test = [r['data-ds-appid'] for r in soup.find_all(name="a", attrs={"data-ds-appid":True})]