2016-11-15 5 views
3

PythonでPhantomJSにSSL証明書をインストールするにはどうすればよいですか?PythonのphantomjsにSSL証明書をインストールするには?

what is the correct way to feed an ssl certificate into phantomjs

--ssl-certificates-pathを使用するために、コマンドラインで言います。

+0

あなたは 'service_arg'として必要なcliコマンドを渡そうとしましたか? – jinksPadlock

+0

あなたの質問にリンクされている質問には、2つの良い答えがあります(新しいもの)。何がうまくいかないの? – Vaviloff

+0

@Vaviloffリンクされた質問を見ると、phantomjsコンソールとPythonの実装ではないことがわかります。私の質問は、私が2回言及し、適切にタグを付けたように、Pythonの実装についてです。 – User

答えて

1

コンパイルが«what is the correct way to feed an ssl certificate into phantomjs»答え、«Is there a way to use PhantomJS in Python?»、あなたはセレンを言及していない考慮して、私はあなたの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を使用する別の方法をセレンオートメーションツールのあなたはまた、CLIを経由して、必要なcerttificateファイルを提供しなければならない。この方法:カスタムのSSLキーを提供することは、バージョン2.1からPhantomJSで動作することを

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() 

注意。

+0

ああ、実際にそれを行うためのpythonの方法はありませんが、Pythonからコマンドを実行するだけです。 – User

+0

その後、 'pythonic way'を定義してください。 PhantomJSはPythonパッケージではなく、別々のバイナリで実行されるファイルであるため、どのソリューションもPythonからコマンドを実行します。 – Vaviloff

+1

セレンの例が追加されました。 – Vaviloff

関連する問題