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

时间:2015-11-17 18:16:38

标签: python https phantomjs 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网址?

1 个答案:

答案 0 :(得分:4)

Splinter在底层使用Selenium WebDriver绑定(example),因此您可以简单地传递必要的选项:

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

请参阅PhantomJS failing to open HTTPS site了解为何可能需要这些选项。请查看PhantomJS commandline interface了解更多选项。

相关问题