简体   繁体   English

python - 美丽的汤获得特定的跨度值

[英]python - beautiful soup get specific span value

html html

<span class="percentage" data-qa="score1">
                                95%
                            </span>
<span class="percentage" data-qa="score2">
                                77%
                            </span>

code:代码:

soup.find('span', class_='percentage')

Desire Result:愿望结果:

77%

Actual Results:实际结果:

95%

Question问题

How do you specify the score2 value?

Use the attrs argument to specify attributes in a dictionary.使用attrs参数指定字典中的属性。

soup.find('span', attrs={"class": "percentage", "data-qa": "score2"})

See How to use hyphen inside .find_all of BeautifulSoup?请参阅如何在 BeautifulSoup 的 .find_all 中使用连字符?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM