REMitchell / python-scraping

Code samples from the book Web Scraping with Python http://shop.oreilly.com/product/0636920034391.do
4.42k stars 2.48k forks source link

seleniumBasic.py in Chapter10 - 'Service' object has no attribute 'process' #25

Open xjr7670 opened 8 years ago

xjr7670 commented 8 years ago

Sorry, I am missing the executable path, specific in executable_path=''

my code is same as the book:

#!/usr/bin/env python3

import time
from selenium import webdriver

driver = webdriver.PhantomJS(executable_path='')
driver.get("http://www.pythonscraping.com/pages/javascript/ajaxDemo.html")
time.sleep(3)
print(driver.find_element_by_id("content").text)
driver.close()

but when I run this code, I got this:

Traceback (most recent call last): File "use_selenium.py", line 6, in driver = webdriver.PhantomJS(executable_path='') File "D:\Python34\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py", line 52, in init self.service.start() File "D:\Python34\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start stdout=self.log_file, stderr=self.log_file) File "D:\Python34\lib\subprocess.py", line 848, in init restore_signals, start_new_session) File "D:\Python34\lib\subprocess.py", line 1104, in _execute_child startupinfo) OSError: [WinError 87] ▒▒▒▒▒▒▒▒ Exception ignored in: <bound method Service.del of <selenium.webdriver.phantomjs.service.Service object at 0x000000000307A940>> Traceback (most recent call last): File "D:\Python34\lib\site-packages\selenium\webdriver\common\service.py", line 163, in del self.stop() File "D:\Python34\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop if self.process is None: AttributeError: 'Service' object has no attribute 'process'

I am using windows8.1+python3.4, install selenium by pip3. And it's also this error occurs in my centos6.5 server patform

CrustyBarnacle commented 8 years ago

Is phantom.js installed? Download PhantomJS Did you test the code with the path to phantom.js explicitly included?

From Chapter 10, Executing JavaScript in Python with Selenium

Depending on the location of your PhantomJS installation, you might also need to explicitly point Selenium in the right direction when creating a new PhantomJS WebDriver:

driver = webdriver.PhantomJS(executable_path='/path/to/download/
                             phantomjs-1.9.8-macosx/bin/phantomjs')

For these types of errors, that do not originate in the code from the book, but from selenium or other imported modules ("File D:\Python34\lib\site-packages\selenium\webdriver\common\service.py:), a search on google and or stackoverflow.com is in order.

A quick search via google for: "selenium webdriver AttributeError: 'Service' object has no attribute 'process', would be a good start.

http://stackoverflow.com/questions/37004635/python-selenium-exception-attributeerror-service-object-has-no-attribute-pr

CrustyBarnacle commented 8 years ago

@xjr7670 - Can you please confirm this fixes the issue for you? As this is not a problem with the code as published, can you comment and close this issue out?