问题描述
我正在尝试使用PhantomJS编写刮板,但是即使morph.io文档中的示例也不起作用.我猜问题是"https",我用http测试了它,并且可以正常工作.你能给我个解决办法吗?我使用Firefox对其进行了测试,并且可以正常工作.
I'm trying to use PhantomJS to write a scraper but even the example in the documentation of morph.io is not working. I guess the problem is "https", I tested it with http and it is working. Can you please give me a solution?I tested it using firefox and it works.
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网址上工作?
PhantomJS is not working on https urls?
推荐答案
Splinter将Selenium WebDriver绑定(示例)用于Python在后台进行操作,因此您可以简单地通过以下必要的选择:
Splinter uses the Selenium WebDriver bindings (example) for Python under the hood, so you can simply pass the necessary options like this:
with Browser("phantomjs", service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any']) as browser:
...
请参阅 PhantomJS无法打开HTTPS网站,以了解可能需要这些选项的原因.请查看 PhantomJS命令行界面.
See PhantomJS failing to open HTTPS site for why those options might be necessary. Take a look at the PhantomJS commandline interface for more options.
这篇关于无法使用Splinter在PhantomJS中打开HTTPS页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!