【算是已解决了但不明所以】UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 0:
问题简述
用最简单的自动化代码写了一个打开网页再关闭的过程,但是运行时候一直报错,是编码相关的错误,
找了好多文章都没用,而且网上很多这种问题都是针对处理文本或文件时候的报错,而我只是一个普通的打开关闭网页,
不知道为什么一直报这个错误,苦恼中……
报错代码
# 导包import timefrom selenium import webdriver# 实例化driver = webdriver.Chrome()# 打开网页driver.get("等一秒钟time.sleep(1)# 关闭网页driver.quit() # 问题就出在这里
具体报错
C:\Users\我的个人文件夹\AppData\Local\Programs\Python\Python39\python.exe 【这里是一段文件路径,我用文字代替了,隐藏一下信息,嘿嘿】Traceback (most recent call last): File "这里是一段文件路径", line 114, in driver.quit() File "C:\Users\wings\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 238, in quit self.service.stop() File "C:\Users\wings\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 146, in stop self.send_remote_shutdown_command() File "C:\Users\wings\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 122, in send_remote_shutdown_command request.urlopen("%s/shutdown" % self.service_url) File "C:\Users\wings\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 214, in urlopen return opener.open(url, data, timeout) File "C:\Users\wings\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 517, in open response = self._open(req, data) File "C:\Users\wings\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 534, in _open result = self._call_chain(self.handle_open, protocol, protocol + File "C:\Users\wings\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 494, in _call_chain result = func(*args) File "C:\Users\wings\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 802, in meth(r, proxy, type)) File "C:\Users\wings\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 810, in proxy_open if req.host and proxy_bypass(req.host): File "C:\Users\wings\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 2769, in proxy_bypass return proxy_bypass_registry(host) File "C:\Users\wings\AppData\Local\Programs\Python\Python39\lib\urllib\request.py", line 2736, in proxy_bypass_registry fqdn = socket.getfqdn(rawHost) File "C:\Users\wings\AppData\Local\Programs\Python\Python39\lib\socket.py", line 791, in getfqdn hostname, aliases, ipaddrs = gethostbyaddr(name)UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc4 in position 0: invalid continuation byte
改后不报错代码
# 导包import timefrom selenium import webdriver# 实例化driver = webdriver.Chrome()# 打开网页driver.get("等一秒钟time.sleep(1)# 关闭网页driver.close() # 只修改了这一个地方
关于
关于driver.close()和driver.quit()的区别,我就只知道一个(描述应该没错吧?)
driver.close() # 是关闭当前这个网页窗口driver.quit() # 是关闭整个浏览器窗口
小尾巴~~技术很渣,搬砖过活,找一点点小快乐~~没怎么在网上写过文章,如有错误,欢迎指正,大家一起进步~!!!
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~