Phantomjs添加到环境变量后为什么webdriver.PhantomJS()不能用默认的path参数?
已经将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 <module>
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
try
driver = webdriver.PhantomJS(executable_path="phantomjs.exe")
每一句下面都会有个undefined 是命令行带的,同浏览器的控制台 可忽略