python - selenium学习问题,找不到解决方法了

查看:524
本文介绍了python - selenium学习问题,找不到解决方法了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

from selenium import webdriver
print(0)
driver = webdriver.PhantomJS(executable_path='E:\phantomjs-2.1.1-windows\bin')
print(1)
driver.get('http://www.baidu.com')
print(2)
print(driver.title)

出错了:
0
Traceback (most recent call last):
File "E:PythonPython35-32libsite-packagesseleniumwebdrivercommonservice.py", line 64, in start

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

File "E:PythonPython35-32libsubprocess.py", line 947, in init

restore_signals, start_new_session)

File "E:PythonPython35-32libsubprocess.py", line 1224, in _execute_child

startupinfo)

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

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/ty/PycharmProjects/untitled3/src/Reptile.py", line 20, in <module>

driver = webdriver.PhantomJS(executable_path='E:\phantomjs-2.1.1-windows\bin')

File "E:PythonPython35-32libsite-packagesseleniumwebdriverphantomjswebdriver.py", line 52, in init

self.service.start()

File "E:PythonPython35-32libsite-packagesseleniumwebdrivercommonservice.py", line 71, in start

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

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

Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.phantomjs.service.Service object at 0x00276A70>>
Traceback (most recent call last):
File "E:PythonPython35-32libsite-packagesseleniumwebdrivercommonservice.py", line 163, in del

self.stop()

File "E:PythonPython35-32libsite-packagesseleniumwebdrivercommonservice.py", line 135, in stop

if self.process is None:

AttributeError: 'Service' object has no attribute 'process'

找不到问题出哪
就到webdriver.PhantomJS这一行出错。
谢谢

解决方案

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

这里提示了,应该把phantomjs的路径加到系统变量PATH里.
测试能用.

这篇关于python - selenium学习问题,找不到解决方法了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆