2015-07-19 230 views
2

我使用硒和PhantomJS与我写一个Python脚本,我有开始通过脚本PhantomJS服务的困难,我不断收到此错误: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)上运行。

回答

1

我在Mac OS上遇到了类似症状的问题。安装从here下载的补丁PhantomJS二进制文件帮助我解决了这个问题。