[英]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.