簡體   English   中英

如何在Python phantomjs中安裝SSL證書?

[英]How to install SSL certificate in Python phantomjs?

如何使用python在PhantomJS中安裝SSL證書?

將ssl證書提供給phantomjs的正確方法是什么?

在命令行中說,使用--ssl-certificates-path

編譯答案«將ssl證書提供給phantomjs的正確方法是什么?«有沒有辦法在Python中使用PhantomJS?»並考慮到你沒有提到Selenium,我想你的python腳本看起來類似於這個:

command = "phantomjs --ignore-ssl-errors=true --ssl-client-certificate-file=C:\tmp\clientcert.cer --ssl-client-key-file=C:\tmp\clientcert.key --ssl-client-key-passphrase=1111 /path/to/phantomjs/script.js"

process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE)

# make sure phantomjs has time to download/process the page
# but if we get nothing after 30 sec, just move on
try:
    output, errors = process.communicate(timeout=30)
except Exception as e:
    print("\t\tException: %s" % e)
    process.kill()

# output will be weird, decode to utf-8 to save heartache
phantom_output = ''
for out_line in output.splitlines():
    phantom_output += out_line.decode('utf-8')

在Python中使用PhantomJS的另一種方法是借助Selenium自動化工具。 這樣您還必須通過CLI提供必要的證明文件:

from selenium import webdriver

driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true', '--ssl-client-certificate-file=C:\tmp\clientcert.cer', '--ssl-client-key-file=C:\tmp\clientcert.key', '--ssl-client-key-passphrase=1111'])
driver.set_window_size(1280, 1024)
driver.get('https://localhost/test/')
driver.save_screenshot('screen.png')
driver.quit()

請注意,提供自定義ssl鍵可以在2.1版的PhantomJS中使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM