Search code examples
pythonbeautifulsoupdata-extraction

How to collect the number of reviews in this case? From a bs4.element.ResultSet object after its extraction


My code :

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")

Result is

<h2 class="_14i3z6h" id="review-section-title" tabindex="-1"><div class="_1p0spma2">15 reviews</div></h2>

Would like to extract the number of reviews from this(ie:15 in this case)


Solution

  • div_text = rev[0].find('div').text
    

    This will return "15 reviews". To get the number, you can do:

    div_number = int(div_text.split(' ')[0])