我的代码:
import requests
from bs4 import BeautifulSoup as bs
url='https://www.airbnb.co.in/users/show/99824610?locale=en&_set_bev_on_new_domain=1589266654_LWYO88OQQwWrgMw2'
page = requests.get(url)
soup = bs(page.content, 'html.parser')
rev=soup.find_all(id="review-section-title",class_="_14i3z6h")
结果是
<h2 class="_14i3z6h" id="review-section-title" tabindex="-1"><div class="_1p0spma2">15 reviews</div></h2>
想从中提取评论数量(即:本例中为 15
(div_text = rev[0].find('div').text
这将返回"15 条评论"。要获取号码,您可以执行以下操作:
div_number = int(div_text.split(' ')[0])