I'm trying to scrap some datas from a website, I can actually get them but they're written in 2 different strings looking like that in my .csv:
aaa
bbb
ccc
and the other:
xxx
yyy
zzz
I'd like to write them following this format:
aaa | xxx
bbb | yyy
ccc | zzz
Here is the code I wrote so far :
# import libraries
import urllib2
from bs4 import BeautifulSoup
import csv
i =0
# specify the url
quote_page = 'http://www.alertepollens.org/gardens/garden/1/state/'
# query the website and return the html to the variable 'page'
response = urllib2.urlopen(quote_page)
# parse the html using beautiful soap and store in variable `soup`
soup = BeautifulSoup(response, 'html.parser')
test = soup
with open('allergene.csv', 'w') as csv_file:
writer = csv.writer(csv_file)
pollene = (("".join(soup.strings)[65:]).encode('utf-8')).replace(' ','').replace('\n',' ').replace(' ',' ').replace(' ',' ').replace(' ','\n')
print pollene
state = (([img['alt'] for img in soup.find_all('img', alt=True)])).
print state.encode
polen = ''.join(pollene)
for item in state:
writer.writerow([item])
for item2 in pollene:
writer.writerow([item2])
One of the main problem is that I have french characters (é, ù, à, etc) and using "strip()" doesn't show these characters correctly.
Do you have any idea how I can do that?