python在win7中不能运行,在Windows 7中无法使用Python启动PhantomJS

I'm trying to use PhantomJS with Python in my Windows 7, but is not working!

Here what i tried to do.

First, i installed webdriver. In the following code Firefox opens normally, so i believe webdrive is correctly installed.

from selenium import webdriver

browser = webdriver.Firefox()

browser.get('http://seleniumhq.org/')

Then, i downloaded PhantomJS from the official website, unpacked it and put it in c:\Phantomjs. Then i added it in Environment Variables.

Here what is in there:

C:\Phantom\phantomjs-2.0.0-windows\bin

So, when i type "phantomjs" in my terminal, it starts normally. But the following code gives me an error:

from selenium import webdriver

browser = webdriver.PhantomJS( )

Error message:

Exception ignored in: >

Traceback (most recent call last):

File "c:Python34\lib\site-packages\selenium\webdriver\common\service.py", line 136, in del

File "c:Python34\lib\site-packages\selenium\webdriver\common\service.py", line 124, in stop

AttributeError: 'NoneType' object has no attribute 'close'

And here if i change a little bit the code:

from selenium import webdriver

browser = webdriver.PhantomJS(executable_path='C:\Phantom\phantomjs-2.0.0-windows\bin\phantomjs.exe')

Error message:

Traceback (most recent call last):

File "c:Python34\lib\site-packages\selenium\webdriver\common\service.py", line 62, in start

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

File "c:Python34\lib\subprocess.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] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

File "d:\test.py", line 2, in

browser = webdriver.PhantomJS(executable_path='C:\Phantom\phantomjs-2.0.0-windows\bin\phantomjs')

File "c:Python34\lib\site-packages\selenium\webdriver\common\service.py", line 51, in init self.service.start( )

File "c:Python34\lib\site-packages\selenium\webdriver\common\service.py", line 69, in start os.path.basename(self.path),

self.start_error_message)

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

Exception ignored in: del of

>

Traceback (most recent call last):

File "c:Python34\lib\site-packages\selenium\webdriver\common\service.py", line 136, in del self.stop( )

File "c:Python34\lib\site-packages\selenium\webdriver\common\service.py", line 117, in stop

if self.process is None:

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

How can i fix it?

解决方案

The problem is that the exe extension is missing in your path.

Try this:

from selenium import webdriver

phantomjs_path = r'C:\Phantom\phantomjs-2.0.0-windows\bin\phantomjs.exe'

browser = webdriver.PhantomJS(phantomjs_path)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值