I'm not quite sure what I need to do with this error. I suggested that this is due to the need to add .encode ('utf-8'). But I'm not quite sure what I need to do, and where I should apply it.
Error:
line 40, in <module> writer.writerows(list_of_rows) UnicodeEncodeError: 'ascii' codec can't encode character u'\u2013' in position 1 7: ordinal not in range(128)
This is the base of my python script.
import csv from BeautifulSoup import BeautifulSoup url = \ 'https://dummysite' response = requests.get(url) html = response.content soup = BeautifulSoup(html) table = soup.find('table', {'class': 'table'}) list_of_rows = [] for row in table.findAll('tr')[1:]: list_of_cells = [] for cell in row.findAll('td'): text = cell.text.replace('[','').replace(']','') list_of_cells.append(text) list_of_rows.append(list_of_cells) outfile = open("./test.csv", "wb") writer = csv.writer(outfile) writer.writerow(["Name", "Location"]) writer.writerows(list_of_rows)
source share