How do I install a SSL certificate in PhantomJS with python?
what is the correct way to feed an ssl certificate into phantomjs
Says in the command line, to use --ssl-certificates-path
.
How do I install a SSL certificate in PhantomJS with python?
what is the correct way to feed an ssl certificate into phantomjs
Says in the command line, to use --ssl-certificates-path
.
Compiling answers «what is the correct way to feed an ssl certificate into phantomjs» and «Is there a way to use PhantomJS in Python?» and taking into consideration that you haven't mentioned Selenium, I suppose your python script would look similar to this:
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')
Another way to use PhantomJS from Python is with the help of Selenium automation tool. This way you would have to also provide necessary certtificate files via 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()
Note that providing custom ssl keys works in PhantomJS from version 2.1.