以下程序显示unicode错误
Date
错误:
import urllib2
import csv
import requests
from 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 = []
for row in table.findAll('tr'):
list_of_cells = []
for 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)
如何解决此错误?
答案 0 :(得分:0)
path ='C:\ Users \ ANIRBAN ROY \ Desktop \ sentiment2020 \ negetive'
files = [] 对于os.walk(path)中的r,d,f: 对于f中的文件: 如果文件中有“ .txt”: files.append(os.path.join(r,file))
对于文件中的f: 打印(f)
file=codecs.open(f,"r","Utf-8")
words=file.split()
# break the string into list of words
str = words
str2 = []
# loop till string values present in list str
for i in str:
# checking for the duplicacy
if i not in str2:
# insert value in str2
str2.append(i)
for i in range(0, len(str2)):
# count the frequency of each word(present
# in str2) in str and print
print('Frequency of', str2[i], 'is :', str.count(str2[i]))
file2= codecs.open('abc.txt','w','utf8')
for line in words:
file2.write(line)
file2.write("\n")
file.close()