在这种情况下如何收集评论数?来自提取后的 bs4.element.ResultSet 对象
How to collect the number of reviews in this case? From a bs4.element.ResultSet object after its extraction
我的代码:
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
这将 return“15 条评论”。要获取号码,您可以这样做:
div_number = int(div_text.split(' ')[0])
我的代码:
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
这将 return“15 条评论”。要获取号码,您可以这样做:
div_number = int(div_text.split(' ')[0])