Note that there are some explanatory texts on larger screens.

plurals
  1. POPython-Unable to locate CSS class using BeautifulSoup
    primarykey
    data
    text
    <p>I'm writing a script to collect weather data from a webpage. My code goes as follows:</p> <pre><code>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) </code></pre> <p>So <code>right_now</code> and <code>feels_like</code> print fine, but when it comes to <code>td_base</code>, it returns either <code>None</code> or <code>[]</code>, an empty list depending on whether using <code>.find</code> or <code>.find_all</code>. To paraphrase in regards to the HTML source code, my code is able to locate <code>itemprop="temperature-fahrenheit"</code> and <code>itemprop="feels-like-temperature-fahrenheit"</code>, but fails on <code>class_="wx-temperature"</code>. I'd appreciate any thoughts about why the first two would succeed but not the third one. Thank you! </p> <p>P.S.: Here is an excerpt of the html source code that is relevant(IMO) to the task at hand:</p> <pre><code>&lt;div class="wx-data-part wx-first"&gt; &lt;div class="wx-temperature"&gt;&lt;span itemprop="temperature-fahrenheit"&gt;87&lt;/span&gt;&lt;span class="wx-degrees"&gt;&amp;deg;&lt;span class="wx-unit"&gt;F&lt;/span&gt;&lt;/span&gt;&lt;/div&gt; &lt;div class="wx-temperature-label"&gt;FEELS LIKE &lt;span itemprop="feels-like-temperature-fahrenheit"&gt;93&lt;/span&gt;&amp;deg;&lt;/div&gt; &lt;/div&gt; &lt;div class="wx-data-part"&gt; &lt;div class="wx-temperature"&gt;94&lt;span class="wx-degrees"&gt;&amp;deg;&lt;/span&gt;&lt;/div&gt; &lt;div class="wx-temperature-label"&gt;HIGH AT 3:25 PM&lt;/div&gt; &lt;/div&gt; &lt;div class="wx-data-part"&gt; &lt;div class="wx-temperature"&gt;76&lt;span class="wx-degrees"&gt;&amp;deg;&lt;/span&gt;&lt;/div&gt; &lt;div class="wx-temperature-label"&gt;LOW&lt;/div&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload