Beautiful Soup – 获取HTML中非标准标签中的特定数值

huangapple go评论68阅读模式
英文:

python - Beautiful soup - get specific value in html not standard tag

问题

86
英文:

Fairly new to beautiful soup. Trying to parse this tag

html

<score-bill scoreA="86" audiencestate="upright" data-qa="score-panel" data-scoresmanager="scorebill:scoreAction" id="scoreboard" mediatype="assetseries" rating="" skeleton="panel" scoreb="98" assetstate="active">

Desired Results

86

Question

How do I parse the value in this tag?

Any help would be greatly appreciated

答案1

得分: 0

你可以使用find来搜索标签。

html = '<score-bill scoreA="86" audiencestate="upright" data-qa="score-panel" data-scoresmanager="scorebill:scoreAction" id="scoreboard" mediatype="assetseries" rating="" skeleton="panel" scoreb="98" assetstate="active">'
soup = BeautifulSoup(html, 'lxml')
results = soup.find('score-bill')['scorea']
print(results) # 86
英文:

You can search the tag with find

html = &#39;&lt;score-bill scoreA=&quot;86&quot; audiencestate=&quot;upright&quot; data-qa=&quot;score-panel&quot; data-scoresmanager=&quot;scorebill:scoreAction&quot; id=&quot;scoreboard&quot; mediatype=&quot;assetseries&quot; rating=&quot;&quot; skeleton=&quot;panel&quot; scoreb=&quot;98&quot; assetstate=&quot;active&quot;&gt;&#39;
soup = BeautifulSoup(html, &#39;lxml&#39;)
results = soup.find(&#39;score-bill&#39;)[&#39;scorea&#39;]
print(results) # 86

huangapple
  • 本文由 发表于 2023年5月24日 19:16:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76322954.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定