我正在使用Selenium和PhantomJS以及我正在编写的Python脚本,我在通过脚本启动PhantomJS服务时遇到困难,我不断收到此错误:
Traceback (most recent call last):
File "asp_scraper.py", line 59, in <module>
scraper = DanishScraper()
File "asp_scraper.py", line 20, in __init__
self.driver = webdriver.PhantomJS(executable_path='./phantomjs/bin/phantomjs')
File "/Library/Python/2.7/site-packages/selenium/webdriver/phantomjs/webdriver.py", line 53, in __init__
self.service.start()
File "/Library/Python/2.7/site-packages/selenium/webdriver/phantomjs/service.py", line 84, in start
raise WebDriverException("Can not connect to GhostDriver")
selenium.common.exceptions.WebDriverException: Message: Can not connect to GhostDriver
这是我到目前为止我的应用程序:
import re
import string
import urlparse
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchElementException, WebDriverException
from bs4 import BeautifulSoup
class DanishScraper(object):
def __init__(self):
self.url = "http://www.realtor.ca/RealtorSearch.aspx"
self.driver = webdriver.PhantomJS(executable_path='./phantomjs/bin/phantomjs')
self.driver.set_window_size(1120, 550)
def scrape(self):
self.driver.get(self.url)
# Select state selection dropdown
select = Select(self.driver.find_element_by_id('ProvinceIds'))
option_indexes = range(1, len(select.options))
for index in option_indexes:
select.select_by_index(index)
self.driver.find_element_by_id
print option_indexes
if __name__ == '__main__':
scraper = DanishScraper()
scraper.scrape()
是否可能与可执行文件的位置有关?我使用Python 2.7在Mac OS 10.11(El Capitan)上运行。