可以使用字符串分割的方法,将字符串按空格分割成一个列表,然后取第一个元素即可:

tag = soup.find('div', {'class': 'review-score-capla'}).text.strip()
score = tag.split()[0]
print(score)

输出结果为:

8.5
tag =soupfinddiv class review-score-caplatextstrip printtag输出是85 非常好2条住客点评如何写输出85这个值

原文地址: https://www.cveoy.top/t/topic/evzt 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录