Beautifulsoup loop through HTML
<p>As mentioned in the previous question, I am using Beautiful soup with python to retrieve weather data from a website.</p>

<p>Here's how the website looks like:</p>

<pre><code>&lt;channel&gt;
&lt;title&gt;2 Hour Forecast&lt;/title&gt;
&lt;source&gt;Meteorological Services Singapore&lt;/source&gt;
&lt;description&gt;2 Hour Forecast&lt;/description&gt;
&lt;item&gt;
&lt;title&gt;Nowcast Table&lt;/title&gt;
&lt;category&gt;Singapore Weather Conditions&lt;/category&gt;
&lt;forecastIssue date="18-07-2016" time="03:30 PM"/&gt;
&lt;validTime&gt;3.30 pm to 5.30 pm&lt;/validTime&gt;
&lt;weatherForecast&gt;
&lt;area forecast="TL" lat="1.37500000" lon="103.83900000" name="Ang Mo Kio"/&gt;
&lt;area forecast="SH" lat="1.32100000" lon="103.92400000" name="Bedok"/&gt;
&lt;area forecast="TL" lat="1.35077200" lon="103.83900000" name="Bishan"/&gt;
&lt;area forecast="CL" lat="1.30400000" lon="103.70100000" name="Boon Lay"/&gt;
&lt;area forecast="CL" lat="1.35300000" lon="103.75400000" name="Bukit Batok"/&gt;
&lt;area forecast="CL" lat="1.27700000" lon="103.81900000" name="Bukit Merah"/&gt;` 
&lt;channel&gt;
</code></pre>

<p>I managed to retrieve forecastIssue date &amp; validTime. However, I am not able to retrieve the different area forecast.</p>

<p>Here are my python codes :</p>

<pre><code>import requests
from bs4 import BeautifulSoup
import urllib3

outfile = open('C:\scripts\idk.xml','w')

#getting the time

r = requests.get('http://www.nea.gov.sg/api/WebAPI/?   
dataset=2hr_nowcast&amp;keyref=&lt;keyrefno&gt;')
soup = BeautifulSoup(r.content, "xml")
time = soup.find('validTime').string
print time

#print issue date and time
for currentdate in soup.findAll('item'):
string = currentdate.find('forecastIssue')
print string
</code></pre>

<p>This is the part where I want to retrieve area forecast eg. <strong>area forecast="TL" lat="1.37500000" lon="103.83900000" name="Ang Mo Kio"/</strong></p>

<pre><code>for area in soup.findAll('weatherForecast'):
areastring = area.find('area')
print areastring
</code></pre>

<p>When I run my codes in python, it only retrieved the first area which is Ang Mo Kio</p>

<p>Sample output: </p>

<pre><code>2.30 pm to 5.30 pm
&lt;forecastIssue date="22-07-2016" time="02:30 PM"/&gt;
&lt;area forecast="RA" lat="1.37500000" lon="103.83900000" name="Ang Mo Kio"/&gt;
</code></pre>

<p><a href="http://i.stack.imgur.com/RM7wb.png" rel="nofollow">Inspect element of the website</a></p>

<p>As you can see, area forecast is within <strong>div class</strong></p>

<ol>
<li><p>How do I loop through all the areas? I've tried googling but apparently findAll doesn't seem to work for my codes </p></li>
<li><p>Is there any way to split the date and time?</p></li>
<li><p>Is there any way I can parse data retrieved by beautifulsoup into a xml file? As my output doesn't contain any data when I run the codes.</p></li>
</ol>

<p>Thank you.</p>