请问python大神写的python代码,我的代码哪里错了?

我的电脑是64位的,安装的这个lxml包就是在~gohlke/pythonlibs/ 网站上找到的,不能导入 etree?这么多lxml 包
Win 64位应该安装哪个包?
我的问题已经解决了
,我下载错了lxml包
不用麻烦老师了
@ 不要告诉我是版本不对或者是下错了位数。。
@ 怎么解决的?
我也碰到了这个问题,看了大家的提问终于解决了。问题和楼主一样。我用的Python27,64位。在老师给的~gohlke/pythonlibs/#lxml这个网址上下载的时候没有选对Python版本号,出现了和大家一样的问题,选择了图片中第二个包,重新下载一个和python版本相同、位数相同的过去一覆盖就解决了,一个多小时了刚弄好,跟大家分享!
03月09日 回答
你好 请问我在哪里可以问问题呢?
03月09日 回答
可以借个楼吗?我不知道在那提问,看到的同学帮下忙,谢谢。这几天看了老师的单线程和XPath多线程,代码down下来,运行没问题,但是写入本地文件数据是空的,谁能解答下啊,急!!!
XPath 与多线程爬虫查看:4750|回复:19
我刚学Python不久,最近正练习使用Python+Webdriver开发自动化测试程序,但刚起步时就遇到了极大的困难:浏览器没法打开。
源码如下:复制内容到剪贴板代码:import sys
from selenium import webdriver
reload(sys)
sys.setdefaultencoding('utf-8')
MyDriver = webdriver.Firefox()
MyDriver.get('')-------------------------------------------------------------------------------------------------------------
错误信息如下:
Traceback (most recent call last):
&&File &D:\python\1.py&, line 6, in &module&
& & MyDriver = webdriver.Firefox()
&&File &c:\python26\lib\site-packages\selenium-2.25.0-py2.6.egg\selenium\webdriv
er\firefox\webdriver.py&, line 51, in __init__
& & self.binary, timeout),
&&File &c:\python26\lib\site-packages\selenium-2.25.0-py2.6.egg\selenium\webdriv
er\firefox\extension_connection.py&, line 45, in __init__
& & self.profile.add_extension()
&&File &c:\python26\lib\site-packages\selenium-2.25.0-py2.6.egg\selenium\webdriv
er\firefox\firefox_profile.py&, line 134, in add_extension
& & self._install_extension(extension)
&&File &c:\python26\lib\site-packages\selenium-2.25.0-py2.6.egg\selenium\webdriv
er\firefox\firefox_profile.py&, line 307, in _install_extension
& & addon_path = os.path.join(extensions_path, addon_id)
&&File &C:\Python26\lib\ntpath.py&, line 107, in join
& & path += &\\& + b
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb2 in position 9: unexpecte
d code byte
————————————————————————————————————————————
我在网上找了不少解决方案,但是没能成功,请各位牛人帮帮忙,如能解决感激不尽
本帖最后由 bldevil 于
14:43 编辑
十万火急啊,求大神们出现
优秀技术经理
encoding=utf8试试呢
引用:原帖由 gm100861 于
17:54 发表
encoding=utf8试试呢 是不是得在encoding=utf8前面加#号,否则编译会不通过。
但加了#号编译后还是出现报错信息:Traceback (most recent call last):
&&File &D:\python\1.py&, line 7, in &module&
& & MyDriver = webdriver.Firefox()
&&File &c:\python26\lib\site-packages\selenium-2.25.0-py2.6.egg\selenium\webdriv
er\firefox\webdriver.py&, line 51, in __init__
& & self.binary, timeout),
&&File &c:\python26\lib\site-packages\selenium-2.25.0-py2.6.egg\selenium\webdriv
er\firefox\extension_connection.py&, line 45, in __init__
& & self.profile.add_extension()
&&File &c:\python26\lib\site-packages\selenium-2.25.0-py2.6.egg\selenium\webdriv
er\firefox\firefox_profile.py&, line 134, in add_extension
& & self._install_extension(extension)
&&File &c:\python26\lib\site-packages\selenium-2.25.0-py2.6.egg\selenium\webdriv
er\firefox\firefox_profile.py&, line 307, in _install_extension
& & addon_path = os.path.join(extensions_path, addon_id)
&&File &C:\Python26\lib\ntpath.py&, line 107, in join
& & path += &\\& + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb2 in position 9: ordinal
not in range(128)
貌似是utf8没有起作用
本帖最后由 bldevil 于
08:56 编辑
再补充一下故障现象:
1、不加utf8编码,报错:
UnicodeDecodeError: 'ascii' codec can't decode byte 0xb2 in position 9: ordinal not in range(128)
2、加了utf8编码,报错:
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb2 in position 9: unexpected code byte
我查了一下报错的文件C:\Python26\lib\ntpath.py,貌似是个调用函数时自带的文件
中级工程师
大圣(神),你在哪,快来解救这个孩子吧!;P1
助理工程师
楼主你用什么编辑python的代码?notepad??
楼主的报错就是在代码没有标示utf-8
你可以下载notepad++,把你的代码copy到notepad++,在encoding下选择“UTF-8”即可
给予意见!
优秀技术经理
引用:原帖由 901IT 于
11:19 发表
楼主你用什么编辑python的代码?notepad??
楼主的报错就是在代码没有标示utf-8
你可以下载notepad++,把你的代码copy到notepad++,在encoding下选择“UTF-8”即可 分析的有道理,不管什么编辑器,在WINDOWS都默认是ANSI编码的,要另存为UTF-8,自带的词本好像没这功能吧???没试过。楼主可以试一下楼上的方法。
引用:原帖由 901IT 于
11:19 发表
楼主你用什么编辑python的代码?notepad??
楼主的报错就是在代码没有标示utf-8
你可以下载notepad++,把你的代码copy到notepad++,在encoding下选择“UTF-8”即可 感谢你的回答!
按照你的方法试了一下,还是报错
助理工程师
引用:原帖由 bldevil 于
14:49 发表
感谢你的回答!
按照你的方法试了一下,还是报错 同样的报错?
助理工程师
引用:原帖由 bldevil 于
14:49 发表
感谢你的回答!
按照你的方法试了一下,还是报错 如果是同样的报错在python头部加入以下:
import sys
reload(sys)
sys.setdefaultencoding(&utf-8&)
你的问题可能是中文的系统,如果可以最好把你的语言设置为English(United State),虽然没看到你的系统,但是你的输入法应该设置成了English(United State)以外的语言。
如果好用了,回复一下。
引用:原帖由 901IT 于
14:58 发表
如果是同样的报错在python头部加入以下:
import sys
reload(sys)
sys.setdefaultencoding(&utf-8&)
你的问题可能是中文的系统,如果可以最好把你的语言设置为English(United State),虽然没看到你的系统,但是你的输入法 ... 901IT兄,错误依旧,应该不是输入法的问题,因为这段程序在语法上没问题,是能够编译通过的
助理工程师
引用:原帖由 bldevil 于
09:06 发表
901IT兄,错误依旧,应该不是输入法的问题,因为这段程序在语法上没问题,是能够编译通过的 但是UnicodeDecodeError: 'ascii' codec can't decode byte 0xb2 in position 9: ordinal
not in range(128)
上面的报错的确是在说ascii不能decode,在头部填写defaultencoding后依然显示相同的报错吗?
程序本身出错不应该是这个报错的,如果不介意,你可以把你的代码和你想要得到的效果发上来,看看能不能帮到你。
引用:原帖由 901IT 于
12:32 发表
但是UnicodeDecodeError: 'ascii' codec can't decode byte 0xb2 in position 9: ordinal
not in range(128)
上面的报错的确是在说ascii不能decode,在头部填写defaultencoding后依然显示相同的报错吗?
程序本身出错不 ... 代码很简单,在1楼就有。代码功能就是用Firefox打开百度首页。
这段程序在我自己的电脑上能够运行成功,但是在公司电脑上运行就报以上错误。
求更多大神帮帮忙啊,周末就得写出来用了,我现在连最基本的程序都运行不了,急啊
助理工程师
你在你公司电脑试试这个。
import webbrowser
webbrowser.open('')
如果firefox不是default
webbrowser.get('firefox').open_new_tab('')
本帖最后由 901IT 于
07:26 编辑
助理工程师
下载webbrowser:
python -m webbrowser -t &http://www.python.org&
我新建了一个操作系统用户,避开公司杀毒软件就没有这个问题了,谢谢大家的热心帮助
我又遇到了同样的问题,但关闭杀毒软件并没有解决问题。
#-*- coding:UTF-8 -*-
from selenium import webdriver
from mon.keys import Keys
driver = webdriver.Firefox()
或者和@bldevil一样的代码,在命令行敲入。
C:\seltests&.\selenv\Scripts\python test.py
Traceback (most recent call last):
&&File &test.py&, line 4, in &module&
& & driver = webdriver.Firefox()
&&File &C:\seltests\selenv\lib\site-packages\selenium\webdriver\firefox\webdrive
r.py&, line 62, in __init__
& & desired_capabilities=capabilities)
&&File &C:\seltests\selenv\lib\site-packages\selenium\webdriver\remote\webdriver
.py&, line 72, in __init__
& & self.start_session(desired_capabilities, browser_profile)
&&File &C:\seltests\selenv\lib\site-packages\selenium\webdriver\remote\webdriver
.py&, line 114, in start_session
& & 'desiredCapabilities': desired_capabilities,
&&File &C:\seltests\selenv\lib\site-packages\selenium\webdriver\remote\webdriver
.py&, line 163, in execute
& & response = mand_executor.execute(driver_command, params)
&&File &C:\seltests\selenv\lib\site-packages\selenium\webdriver\remote\remote_co
nnection.py&, line 349, in execute
& & return self._request(url, method=command_info[0], data=data)
&&File &C:\seltests\selenv\lib\site-packages\selenium\webdriver\remote\remote_co
nnection.py&, line 400, in _request
& & body = response.read().decode('utf-8').replace('\x00', '').strip()
&&File &C:\seltests\selenv\lib\encodings\utf_8.py&, line 16, in decode
& & return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb4 in position 193: invalid
start byte
@求各位大神和楼主指点!这个问题已经困扰我两天了。

我要回帖

更多关于 python代码运行助手 的文章

 

随机推荐