Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Selenium页面无法保存源代码编码错误_Python_Selenium_Unicode - Fatal编程技术网

Python Selenium页面无法保存源代码编码错误

Python Selenium页面无法保存源代码编码错误,python,selenium,unicode,Python,Selenium,Unicode,我试图用Selenium将源代码保存到.txt中,但.txt文件保持为空 当我试图用命令打印源代码时: htmlcode = driver.page_source (driver.page_source).encode('utf-8')) print(htmlcode) 它将打印源代码,但随后会终止脚本并出现错误: File "C:\Python27\lib\encodings\cp850.py", line 12, in encode return codecs.charmap_encode

我试图用Selenium将源代码保存到.txt中,但.txt文件保持为空

当我试图用命令打印源代码时:

htmlcode = driver.page_source
(driver.page_source).encode('utf-8'))
print(htmlcode)
它将打印源代码,但随后会终止脚本并出现错误:

File "C:\Python27\lib\encodings\cp850.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u20ac' in position 16329: character maps to <undefined>
文件“C:\Python27\lib\encodings\cp850.py”,第12行,在encode中
返回编解码器.charmap\u encode(输入、错误、编码\u映射)
UnicodeEncodeError:“charmap”编解码器无法对16329位置的字符u'\u20ac'进行编码:字符映射到

问题已解决!搜索3小时后':-)


你能把保存到文件中的代码贴出来吗?我使用了下面的脚本,但由于编码错误,这不起作用。site=browser.open(link)fileobjj=open(“output.txt”,“wb”)fileobjj.write(site.read())fileobjj.close()
html = driver.page_source
f = open('savepage.html', 'w')
f.write(html.encode('utf-8'))
f.close()