Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Perhaps I misunderstand your question, but you are merely looking for <a href="http://docs.python.org/2/library/re.html#re.findall" rel="nofollow">findall</a>?</p> <pre><code>match3 = re.findall(r'&lt;div class="wx-temperature"&gt;\w\w',f) </code></pre> <p>Also, you might find it easier to use <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">BeautifulSoup</a> or something along those lines. Parsing html with regexes is hellish. Further, you might as well not reinvent the wheel, since python has hundreds of well-built modules that have already done a lot of work for you. You could do the following after installing bs4:</p> <pre><code>&gt;&gt;&gt; from bs4 import BeautifulSoup &gt;&gt;&gt; html = '''&lt;div class="wx-timepart-title"&gt; Earlier Today &lt;/div&gt; &lt;div class="wx-timepart-title"&gt;Tonight&lt;/div&gt; &lt;div class="wx-data-part wx-first"&gt; &lt;img src="http://s.imwx.com/v.20120328.084208/img/wxicon/120/29.png" height="120" width="120" alt="Partly Cloudy" class="wx-weather-icon"&gt; &lt;/div&gt; &lt;div class="wx-data-part"&gt; &lt;img src="http://s.imwx.com/v.20120328.084208/img/wxicon/120/30.png" height="120" width="120" alt="Partly Cloudy" class="wx-weather-icon"&gt; &lt;/div&gt; &lt;div class="wx-data-part"&gt; &lt;img src="http://s.imwx.com/v.20120328.084208/img/wxicon/120/29.png" height="120" width="120" alt="Partly Cloudy" class="wx-weather-icon"&gt; &lt;/div&gt; &lt;div class="wx-data-part wx-first"&gt; &lt;div class="wx-temperature"&gt;&lt;span itemprop="temperature-fahrenheit"&gt;89&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;94&lt;/span&gt;&amp;deg;&lt;/div&gt; &lt;/div&gt; &lt;div class="wx-data-part"&gt; &lt;div class="wx-temperature"&gt;96&lt;span class="wx-degrees"&gt;&amp;deg;&lt;/span&gt;&lt;/div&gt; &lt;div class="wx-temperature-label"&gt;HIGH AT 4:45 PM&lt;/div&gt; &lt;/div&gt; &lt;div class="wx-data-part"&gt; &lt;div class="wx-temperature"&gt;80&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; ''' &gt;&gt;&gt; soup = BeautifulSoup(html) &gt;&gt;&gt; for temp in soup.find_all(class_="wx-temperature"): print(temp.text) # or add these to a list or make a list comprehension 89°F 96° 80° </code></pre> <p>If you merely want the digits (and possibly a negative), you can do this:</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; for temp in soup.find_all(class_="wx-temperature"): print(re.match(r'-?\d+', temp.text).group()) 89 96 80 </code></pre> <p>This approach would give you some flexibility in case the weather ever drops to one digit or goes up to three digits. I added the <code>-?</code>, which means 0 or 1 occurrences of the character <code>-</code>, in case you run across negative temps.</p>
 

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