无法使用 Splinter 在 PhantomJS 中打开 HTTPS 页面

Failing to open HTTPS pages in PhantomJS using Splinter

我正在尝试使用 PhantomJS 编写抓取工具,但即使 morph.io 文档中的示例也无法正常工作。我猜问题出在 "https",我用 http 测试了它,它可以正常工作。你能给我一个解决方案吗? 我使用 firefox 对其进行了测试,它可以正常工作。

from splinter import Browser

with Browser("phantomjs") as browser:
    # Optional, but make sure large enough that responsive pages don't
    # hide elements on you...
    browser.driver.set_window_size(1280, 1024)

    # Open the page you want...
    browser.visit("https://morph.io")

    # submit the search form...
    browser.fill("q", "parliament")
    button = browser.find_by_css("button[type='submit']")
    button.click()

    # Scrape the data you like...
    links = browser.find_by_css(".search-results .list-group-item")
    for link in links:
        print link['href']

PhantomJS 无法处理 https 网址?

Splinter 在后台使用 Python 的 Selenium WebDriver 绑定 (example),因此您可以像这样简单地传递必要的选项:

with Browser("phantomjs", service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any']) as browser:
    ...

有关更多选项,请参阅 for why those options might be necessary. Take a look at the PhantomJS commandline interface