webdriver设置环境变量_Phantomjs添加到环境变量后为什么webdriver.PhantomJS()不能用默认的path参数?...

尽管已将 PhantomJS 添加到环境变量,尝试使用 `webdriver.PhantomJS()` 仍报找不到文件错误。在Python中运行 Selenium 代码时,启动 PhantomJS 服务失败,提示 'phantomjs' 执行文件需要在 PATH 中。同时,CMD 中运行 PhantomJS 每条命令后出现 undefined。
摘要由CSDN通过智能技术生成

已经将phantomjs添加到环境变量中,按照selenium的文档里说这样就可以用webdriver.PhantomJS()的executable_path的默认参数运行了,但实测会报错.

from selenium import webdriver

driver = webdriver.PhantomJS()

driver.get(url)

print(driver.page_source)

driver.quit()

以下是报错内容:

Traceback (most recent call last):

File "D:Pythonlibsite-packagesseleniumwebdrivercommonservice.py", line 74, in start

stdout=self.log_file, stderr=self.log_file)

File "D:Pythonlibsubprocess.py", line 707, in init

restore_signals, start_new_session)

File "D:Pythonlibsubprocess.py", line 990, in _execute_child

startupinfo)

FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "F:/ProgrammingWorkspaces/Python/BbGrade/tests/selenium_test.py", line 3, in

driver = webdriver.PhantomJS()

File "D:Pythonlibsite-packagesseleniumwebdriverphantomjswebdriver.py", line 52, in init

self.service.start()

File "D:Pythonlibsite-packagesseleniumwebdrivercommonservice.py", line 81, in start

os.path.basename(self.path), self.start_error_message)

selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH

另外还有个小问题是为什么cmd中用phantomjs每一句下面都会有个undefined

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值