python3.4+ selenium3.0 连续报错
selenium吧
全部回复
仅看楼主
level 1
tonychiu2010 楼主
我在python3.4下装好selenium3.0, 运行以下代码测试
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://www.baidu.com')
结果报错如下:
>>>
Traceback (most recent call last):
File "F:\爬虫\esuppliersindia\test.py", line 1, in <module>
from selenium import webdriver
File "C:\Python34\lib\site-packages\selenium-3.0.0b2-py3.4.egg\selenium\webdriver\__init__.py", line 25, in <module>
from .safari.webdriver import WebDriver as Safari # noqa
File "C:\Python34\lib\site-packages\selenium-3.0.0b2-py3.4.egg\selenium\webdriver\safari\webdriver.py", line 49
executable_path = os.environ.get("SELENIUM_SERVER_JAR")
^
TabError: inconsistent use of tabs and spaces in indentation
>>>
我查了...\safari\webdriver.py文件,看到这样的代码
if not executable_path is None:
executable_path = os.environ.get("SELENIUM_SERVER_JAR")
self.service = Service(executable_path, port=port, quiet=quiet,use_legacy=use_legacy_driver)
self.service.start()
联想到py3要求tab和space不能混用,于是我吧 executable_path之前的空格删掉,再打8个空格,这样又报错:
executable_path = os.environ.get("SELENIUM_SERVER_JAR")
^
IndentationError: expected an indented block
于是我把 if not executable_path is None: 下的3句缩进,就是这样,
if not executable_path is None:
executable_path = os.environ.get("SELENIUM_SERVER_JAR")
self.service = Service(executable_path, port=port, quiet=quiet, use_legacy=use_legacy_driver)
self.service.start()
这下问题更大了,报错如下:
>>>
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\selenium-3.0.0b2-py3.4.egg\selenium\webdriver\common\service.py", line 64, in start
stdout=self.log_file, stderr=self.log_file)
File "C:\Python34\lib\su
bp
rocess.py", line 859, in __init__
restore_signals, start_new_session)
File "C:\Python34\lib\subprocess.py", line 1112, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:\爬虫\esuppliersindia\test.py", line 2, in <module>
driver = webdriver.Firefox()
File "C:\Python34\lib\site-packages\selenium-3.0.0b2-py3.4.egg\selenium\webdriver\firefox\webdriver.py", line 65, in __init__
self.service.start()
File "C:\Python34\lib\site-packages\selenium-3.0.0b2-py3.4.egg\selenium\webdriver\common\service.py", line 71, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
>>>
这下我是真没辙了,各位大神有没有遇到同样的问题呢?请教。
2016年08月05日 17点08分 1
level 8
是不是少了,#coding:utf-8
2016年08月09日 01点08分 2
level 1
楼主如何解决的
2016年08月18日 14点08分 3
level 1
我的也是这样
2016年08月26日 00点08分 4
level 1
缩进三行的做法是对的,这里也有人提:
http://stackoverflow.com/questions/38917412/python3-5-2-selenium-3-0-0b2-firefox-48-0-inconsistent-use-of-tabs-and-spaces
这个是其他的问题,我用MAC也出现了,现在的问题主要是看geckodriver这个有没有装,然后装了的话有没有放在PATH里
2016年09月11日 00点09分 6
level 1
geckodriver,火狐浏览器更新后selenium3.0 更新,我去年写的爬虫都不能用了,发现需要下geckodriver,
2016年10月04日 04点10分 8
level 1
这个问题有谁知道解决办法??
2018年02月07日 08点02分 9
1