title: How to make BeautifulSoup output more consistent
body: <p>I have the following code to print number of home listings on Airbnb page:</p>
  
  <pre><code>import requests, bs4
  
  url = 'https://www.airbnb.pl/s/Girona--Hiszpania/homes?place_id=ChIJRRrTHsPNuhIRQMqjIeD6AAM&amp;query=Girona%2C%20Hiszpania&amp;refinement_paths%5B%5D=%2Fhomes&amp;allow_override%5B%5D=&amp;s_tag=b5bnciXv'
  response = requests.get(url)
  soup = bs4.BeautifulSoup(response.text)
  
  listings = soup.select('._f21qs6')
  
  print(len(listings))
  </code></pre>
  
  <p>The print output should be "18", this is how many listings are on this page.</p>
  
  <p>However, the output is inconsistent. Sometimes I indeed get "18", but other times it is "0".</p>
  
  <p>Is there anything I can improve in this code to make the output more consistent?</p>
  
  <p>EDIT: I have refactored the code to make the inconsistency in output evident:</p>
  
  <pre><code>import requests, bs4
  
  def get_listings():
      url = 'https://www.airbnb.pl/s/Girona--Hiszpania/homes?place_id=ChIJRRrTHsPNuhIRQMqjIeD6AAM&amp;query=Girona%2C%20Hiszpania&amp;refinement_paths%5B%5D=%2Fhomes&amp;allow_override%5B%5D=&amp;s_tag=b5bnciXv'
      response = requests.get(url)
      soup = bs4.BeautifulSoup(response.text, "html.parser")
      listings = soup.select('._f21qs6')
      return listings
  
  def check_if_all_listings_downloaded():
      number_of_listings = len(get_listings())
      print("Current number of listings: " + str(number_of_listings))
      while number_of_listings != 18:
          print("Too few listings: " + str(number_of_listings))
          number_of_listings = len(get_listings())
      print("All fine! The number of listings is: " + str(number_of_listings))
  
  check_if_all_listings_downloaded()
  </code></pre>
  
  <p>Example output of this refactored code is:</p>
  
  <pre><code>Current number of listings: 0
  Too few listings: 0
  Too few listings: 0
  Too few listings: 16
  All fine! The number of listings is: 18
  </code></pre>