0
我正在嘗試PhantomJS,以便使用Selenium和Python運行我的webscrapes,而不需要在scrape循環進入下一頁時打開新窗口。在Python/Selenium中使用PhantomJs
我諮詢這個帖子最初:Is there a way to use PhantomJS in Python?
但是我不得不修改我的道路,以獲得我下面的代碼node.exe:
for link in soup1.findAll('a', {'property_title'}):
#print 'https://www.tripadvisor.com/Restaurant_Review-g294217-' + link.get('href')
restaurant_url = 'https://www.tripadvisor.com/Restaurant_Review-g188590-' + link.get('href')
driver = webdriver.PhantomJS(r"C:\Program Files (x86)\nodejs\node.exe")
driver.get(restaurant_url)
neighborhood = driver.find_element_by_xpath(r'//*[@id="BODYCON"]/div[2]/div/div[2]/div[2]/div[1]/div[1]/div[2]/div[2]/div[2]/ul/li[3]')
restneighborhood = neighborhood.text
print restneighborhood
我得到這個錯誤:
Traceback (most recent call last):
File "C:/Users/dtrinh/PycharmProjects/TripAdvisorData/LinkPull-HK.py", line 23, in <module>
driver = webdriver.PhantomJS(r"C:\Program Files (x86)\nodejs\node.exe")
File "C:\Python27\lib\site-packages\selenium-3.0.1-py2.7.egg\selenium\webdriver\phantomjs\webdriver.py", line 52, in __init__
self.service.start()
File "C:\Python27\lib\site-packages\selenium-3.0.1-py2.7.egg\selenium\webdriver\common\service.py", line 86, in start
self.assert_process_still_running()
File "C:\Python27\lib\site-packages\selenium-3.0.1-py2.7.egg\selenium\webdriver\common\service.py", line 99, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service C:\Program Files (x86)\nodejs\node.exe unexpectedly exited. Status code was: 9
我不知道我在做什麼,因爲我通常使用ChromeDriver,但如果任何人都可以幫助我,那將是非常棒的。