I'm writing a script to collect weather data from a webpage. My code goes as follows:
import urllib.request
from bs4 import BeautifulSoup
# open the webpage and assign the content to a new variable
base = urllib.request.urlopen('http://www.weather.com/weather/today/Washington+DC+20006:4:US')
f = base.readlines()
f = str(f)
soup = BeautifulSoup(f)
rn_base = soup.find(itemprop="temperature-fahrenheit")
right_now = rn_base.string
print(right_now)
fl_base = soup.find(itemprop="feels-like-temperature-fahrenheit")
feels_like = fl_base.string
print(feels_like)
td_base = soup.find_all('class_="wx-temperature"')
print(td_base)
So right_now and feels_like print fine, but when it comes to td_base, it returns either None or [], an empty list depending on whether using .find or .find_all. To paraphrase in regards to the HTML source code, my code is able to locate itemprop="temperature-fahrenheit" and itemprop="feels-like-temperature-fahrenheit", but fails on class_="wx-temperature". I'd appreciate any thoughts about why the first two would succeed but not the third one. Thank you!
P.S.: Here is an excerpt of the html source code that is relevant(IMO) to the task at hand:
<div class="wx-data-part wx-first">
<div class="wx-temperature"><span itemprop="temperature-fahrenheit">87</span><span class="wx-degrees">°<span class="wx-unit">F</span></span></div>
<div class="wx-temperature-label">FEELS LIKE
<span itemprop="feels-like-temperature-fahrenheit">93</span>°</div>
</div>
<div class="wx-data-part">
<div class="wx-temperature">94<span class="wx-degrees">°</span></div>
<div class="wx-temperature-label">HIGH AT 3:25 PM</div>
</div>
<div class="wx-data-part">
<div class="wx-temperature">76<span class="wx-degrees">°</span></div>
<div class="wx-temperature-label">LOW</div>
</div>