I have scraped address data from a site using a For loop which prints out the result. I would like to output all of the results from each of the For loops into separate columns in a CSV file. When I try to output I only get the last iteration through the For loops and all of the bulky HTML code is included. The print street.text prints all of the data located within all span tags that have itemprop = address.
Here is my code so far:
soup = BeautifulSoup(response, "lxml");
for address in soup.find_all('span', {'itemprop' : 'address'}):
print address.text
HTML in question:
<span itemprop="address" itemscope="" itemtype="http://schema.org/PostalAddress" id="yui_3_15_0_1_1405702066072_1576"><a href="/homedetails/403-James-Toney-Dr-Elon-NC-27244/96315551_zpid/" class="hdp-link routable" title="403 James Toney Dr, Elon, NC Real Estate" id="yui_3_15_0_1_1405702066072_1575"><span itemprop="streetAddress" id="yui_3_15_0_1_1405702066072_1574">403 James Toney Dr</span>, <span itemprop="addressLocality">Elon</span>, <span itemprop="addressRegion" id="yui_3_15_0_1_1405702066072_1580">NC</span><span itemprop="postalCode" class="hide">27244</span></a></span>
This prints all of the data in order. However I need to get each instance of address into a CSV column. Is this possible? I was thinking I needed a way to store each address into a variable as the loop iterates, but I've read that this might not be a good solution. I've looked on several websites trying to figure out a solution. I feel like it should be pretty simple, I just can't figure it out.
Edit: I was able to use only 1 loop to get all of the info I need. Hopefully this makes the problem simpler.