python - the program shows unicode error -
the below program shows unicode error
import urllib2 import csv import requests bs4 import beautifulsoup url = 'http://www.icc-cricket.com/associate-affiliate-rankings' response = requests.get(url) html = response.content soup = beautifulsoup(html) table= soup.find('div', attrs={'class': 'associaterankings'}) list_of_rows = [] row in table.findall('tr'): list_of_cells = [] cell in row.findall('td'): text = cell.text.replace(' ', '') list_of_cells.append(text) list_of_rows.append(list_of_cells) outfile = open("./i.csv", "wb") writer = csv.writer(outfile) writer.writerows(list_of_rows)
error:
traceback (most recent call last): file "f:\web\hi.py", line 20, in <module> writer.writerows(list_of_rows) unicodeencodeerror: 'ascii' codec can't encode character u'\xa0' in position 0: ordinal not in range(128)
how fix error?
Comments
Post a Comment