I am trying to retrieve the 'Sold for' value (i.e. $1,040,000) and 'Rating value' (i.e. $640,000) from the below piece of html code.
Here is the code I'm using:
html = '''
<div class="padb-listing-id">
<span>
Listing ID:
</span>
804244
</div>
<div class="padb-property-value">
<span>
Sold for:
</span>
$1,040,000
</div>
<div class="padb-property-rating-value">
<span>
Rating Value:
</span>
$640,000
<span class="padb-rating-date">
(July '17)
</span>
</div>
'''
from bs4 import BeautifulSoup
import requests
soup = BeautifulSoup(html, 'html.parser')
listing_id = soup.find('div', class_='padb-listing-id').text
value = soup.find('div', class_='padb-property_value')
rating_value = soup.find('div', class_='padb-property-rating-value').text
print(f'{listing_id}Price: {value}{rating_value}')
which returns this output:
Listing ID:
804244
Price: None
Rating Value:
$640,000
(July '17)
It brings back 'None' for the 'Sold for' value and I don't know how to fix it. I've looked up a few posts link1, link2, link3 but none of these have worked for me.
I'm new to BeautifulSoup and html so would really appreciate some help.
Thanks!!
P.s. When I add '.text' to the 'value' code I get an AttributeError: 'NoneType' object has no attribute 'text'. Thought I add this here in case anyone wonders why the 'value' code is different from the rest.