第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

UnicodeEncodeError: 'charmap' codec can't encode

UnicodeEncodeError: 'charmap' codec can't encode

BIG陽 2021-09-11 20:30:29
Windows 7 版本 Python36-32 代碼用途:網(wǎng)站解析你能建議錯誤的可能原因是什么?我在開頭包含了編碼 utf-8 和 (encoding = 'windows_1252', errors = 'replace') 在函數(shù)“open”中它幫助我在其他網(wǎng)站的其他類似解析器中,但對于這個不起作用**一段代碼:# cycle through pages     for i in range (count):         s = str (i + 1)         print (s, end = '')         # make url         url = url1 + s + url2 + str (status) + url3         # get html file from server by url         r = requests.get (url)         # open file to save with full path to file name         name = path + 'upload' + s + '.html'         f = open (name, 'w', encoding = 'windows_1252', errors = 'replace')         # save url data to file         f.write (r.text)         # close file         f.close ()         # download files through the list         parseList (name, s + '.html')     print ()     return錯誤文本:Traceback (most recent call last):  File "C:\Users\u6030283\Desktop\FINAM\finam_parser_new.py", line 478, in <module>    parse('list', 'html', 'XS1272198265')  File "C:\Users\u6030283\Desktop\FINAM\finam_parser_new.py", line 262, in parse    f.write(r.text)  File "C:\Users\u6030283\AppData\Local\Programs\Python\Python36-32\lib\encodings\cp1251.py", line 19, in encode    return codecs.charmap_encode(input,self.errors,encoding_table)[0]UnicodeEncodeError: 'charmap' codec can't encode character '\x97' in position 206: character maps to <undefined>
查看完整描述

1 回答

?
尚方寶劍之說

TA貢獻(xiàn)1788條經(jīng)驗(yàn) 獲得超4個贊

更新:


的問題是不能從上述(寫文件),但在代碼parse()也不parseList()方法或從讀取文件。


替換以下內(nèi)容


# in parseList(...)

text = open(url, 'r')


# and in parse(..)

text = open(path + file, 'r') 


# in parseList(...)

text = open(url, 'r', encoding='windows_1252')


# and in parse(..)

text = open(path + file, 'r', encoding='windows_1252') 

并且不要忘記將上述問題中的代碼恢復(fù)到原始狀態(tài)。


查看完整回答
反對 回復(fù) 2021-09-11
  • 1 回答
  • 0 關(guān)注
  • 363 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號