I have two slightly different urls: https://www.booli.se/annons/2278076, https://www.booli.se/bostad/507292
Difference between the first and the second page: In the second page there is no Utropspris (estimated price).
In the first link I will get estimated price (Utropspris) using the following code:
in[1]= soup.findAll('span', class_='property__base-info__value')[1].text.strip() out[1]= u'3 800 000 kr\n\t\t\t64 407 kr/m\xb2' However in the second link using the same code I used above I will get fee (Avgift)
in[2]= soup.findAll('span', class_='property__base-info__value')[1].text.strip() out[2]= u'4 425 kr/m\xe5n' How can I tell my code that in the second link when I used the same code, this is not estimated price (Utropspris) anymore. This is fee (avgift), save it as fee and for the estimated price write NA. This is part of my code that might be helpful.
url=https://www.booli.se/bostad/507292 import requests from bs4 import BeautifulSoup request = requests.get(url) soup = BeautifulSoup(request.text,'lxml') soup.findAll('span', class_='property__base-info__value')[1].text.strip()