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这一行出错。
谢谢

阅读 27.3k
4 个回答
selenium.common.exceptions.WebDriverException: Message: 'phantomjs-2.1.1-windowsin' executable needs to be in PATH.

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

1、判断一个这个文件能否执行
2、判断文件位置是否正确
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题