简体   繁体   English

Python:文件写入错误(UnicodeEncodeError)

[英]Python: File Writing Error (UnicodeEncodeError)

url1 = "https://en.wikisource.org/"+selectedbook['href']
r1 = requests.get(url1)
Soup1 = BeautifulSoup(r1.text, "html5lib")
List1 = Soup1.find("div", class_="prp-pages-output").find_all('p')
words=str(List1)
ebook1= open('ebook1.txt', 'w')
ebook1.write(words)
ebook1.close()

This is the last part of my code.这是我代码的最后一部分。 When I run this, I get this error:运行此命令时,出现以下错误:

Traceback (most recent call last):
  File "homework.py", line 35, in <module>
    ebook1.write(words)
  File "C:\Users\Özdal\AppData\Local\Programs\Python\Python38-32\lib\encodings\cp1254.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u200b' in position 3121: character maps to <undefined>

I just want to download a file that includes paragraghs of this url: https://en.wikisource.org/wiki/Animal_Life_and_the_World_of_Nature/1903/06/Notes_and_Comments我只想下载一个包含以下URL的文件的文件: https ://en.wikisource.org/wiki/Animal_Life_and_the_World_of_Nature/1903/06/Notes_and_Comments

Why do I get this error?为什么会出现此错误?

url1 = "https://en.wikisource.org/"+selectedbook['href']
r1 = requests.get(url1)
Soup1 = BeautifulSoup(r1.text, "html5lib")
List1 = Soup1.find("div", class_="prp-pages-output").find_all('p')
words=str(List1)
ebook1= open('ebook1.txt', 'w')
ebook1.write(words)
ebook1.close()

This is the last part of my code.这是我代码的最后一部分。 When I run this, I get this error:运行此命令时,出现以下错误:

Traceback (most recent call last):
  File "homework.py", line 35, in <module>
    ebook1.write(words)
  File "C:\Users\Özdal\AppData\Local\Programs\Python\Python38-32\lib\encodings\cp1254.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u200b' in position 3121: character maps to <undefined>

I just want to download a file that includes paragraghs of this url: https://en.wikisource.org/wiki/Animal_Life_and_the_World_of_Nature/1903/06/Notes_and_Comments我只想下载一个包含以下URL的文件的文件: https ://en.wikisource.org/wiki/Animal_Life_and_the_World_of_Nature/1903/06/Notes_and_Comments

Why do I get this error?为什么会出现此错误?

url1 = "https://en.wikisource.org/"+selectedbook['href']
r1 = requests.get(url1)
Soup1 = BeautifulSoup(r1.text, "html5lib")
List1 = Soup1.find("div", class_="prp-pages-output").find_all('p')
words=str(List1)
ebook1= open('ebook1.txt', 'w')
ebook1.write(words)
ebook1.close()

This is the last part of my code.这是我代码的最后一部分。 When I run this, I get this error:运行此命令时,出现以下错误:

Traceback (most recent call last):
  File "homework.py", line 35, in <module>
    ebook1.write(words)
  File "C:\Users\Özdal\AppData\Local\Programs\Python\Python38-32\lib\encodings\cp1254.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
UnicodeEncodeError: 'charmap' codec can't encode character '\u200b' in position 3121: character maps to <undefined>

I just want to download a file that includes paragraghs of this url: https://en.wikisource.org/wiki/Animal_Life_and_the_World_of_Nature/1903/06/Notes_and_Comments我只想下载一个包含以下URL的文件的文件: https ://en.wikisource.org/wiki/Animal_Life_and_the_World_of_Nature/1903/06/Notes_and_Comments

Why do I get this error?为什么会出现此错误?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python文件写入显示UnicodeEncodeError的错误 - python file writing shows the error for UnicodeEncodeError 写入文件时出现 UnicodeEncodeError - UnicodeEncodeError when writing to file 写入文件时出现 UnicodeEncodeError - UnicodeEncodeError when writing to a file 为什么Python不能从Latin Extended-A写入字符(写入文件时会出现UnicodeEncodeError)? - Why isn't Python writing characters from Latin Extended-A (UnicodeEncodeError when writing to a file)? 编写简单的查询,获取unicodeEncodeError,python 2.7 - Writing a simple query, getting a unicodeEncodeError, python 2.7 UnicodeEncodeError将具有特殊字符的文本写入文件 - UnicodeEncodeError writing text with special character to file 将亚洲字符写入文件时出现 UnicodeEncodeError - UnicodeEncodeError when writing asian characters to a file 写入csv文件时,writerow因UnicodeEncodeError失败 - when writing to csv file writerow fails with UnicodeEncodeError 将数据写入xml文件时出现UnicodeEncodeError - UnicodeEncodeError while writing data to an xml file 将结果从 python 写入 csv 文件 [UnicodeEncodeError: &#39;charmap&#39; codec can&#39;t encode character - Writing out results from python to csv file [UnicodeEncodeError: 'charmap' codec can't encode character
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM