2017-11-13 18 views
0

セレンの性能を向上させたい(selenium-pythonで作業中)。 GUIは必要ないので、ヘッドレスブラウザに切り替えることを考えました。 私はphantomJSためのパス変数を設定し、(いくつかのstackoverflowの数十とGoogleグループセレンでPhantomJSを使用する

phantomjs_path = r"C:\Users\sachin.nandakumar\AppData\Local\Continuum\anaconda3\phantomjs\bin\phantomjs.exe" 
service_args = [ '--proxy=10.118.132.29:80', '--proxy-type=http',]  
driver = webdriver.PhantomJS(executable_path=phantomjs_path,service_args=service_args)  

を経しかし、私のドライバの初期化中に、私はパスとサービス引数を設定errorを取得する際

driver = webdriver.PhantomJS() 

を走りました同じエラーが発生します(詳細は以下でエラーが発生します)

その後、私もHtmlUnitDriverで試しましたが、同じエラーが再度発生します。

ヘッドレスブラウザがプロキシ(社内のファイアウォール?)の背後で作業する際に問題はありますか?それとも、いくつかの認証の問題については、私はそれらに取り組む方法についての方法を見つけませんでした。

E 
====================================================================== 
ERROR: test_start (__main__.TestWeb) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "...Crawler\crawl_core\src_main\run.py", line 26, in setUp 
    driver =  webdriver.PhantomJS(executable_path=phantomjs_path,service_args=service_args) 
    File "...\anaconda3\lib\site-packages\selenium\webdriver\phantomjs\webdriver.py", line 58, in __init__ 
desired_capabilities=desired_capabilities) 
    File "...\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 151, in __init__ 
self.start_session(desired_capabilities, browser_profile) 
    File "...\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 240, in start_session 
response = self.execute(Command.NEW_SESSION, parameters) 
    File "...\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 308, in execute 
self.error_handler.check_response(response) 
    File "...\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 165, in check_response 
raise exception_class(value) 
selenium.common.exceptions.WebDriverException: Message: <HTML><HEAD> 

<TITLE>Access Denied</TITLE> 

</HEAD> 

<BODY> 

<FONT face="Helvetica"> 

<big><strong></strong></big><BR> 

</FONT> 

<blockquote> 

<TABLE border=0 cellPadding=1 width="80%"> 

<TR><TD> 

<FONT face="Helvetica"> 

<big>Access Denied (authentication_failed)</big> 

<BR> 

<BR> 

</FONT> 

</TD></TR> 

<TR><TD> 

<FONT face="Helvetica"> 

Your credentials could not be authenticated: "General authentication failure due to bad user ID or authentication token.". You will not be permitted access until your credentials can be verified. 

</FONT> 

</TD></TR> 

<TR><TD> 

<FONT face="Helvetica"> 

This is typically caused by an incorrect username and/or password, but could also be caused by network problems. 

</FONT> 

</TD></TR> 

<TR><TD> 

<FONT face="Helvetica" SIZE=2> 

<BR> 

For assistance, contact your network support team. 

</FONT> 

</TD></TR> 

</TABLE> 

</blockquote> 

</FONT> 

</BODY></HTML> 

答えて

1

PhantomJSはもはや積極的に開発されていません。だからあなたはPhantomJSを走らせるべきではありません。クロムに切り替えるとうまくいくはずです。プロキシが認証を要求するかどうかを確認します。

はここからchromedriver取得、https://sites.google.com/a/chromium.org/chromedriver/downloads

+0

私はどこでも、この前にその情報を発見したことはありませんが、それは私は非常に便利に来ました!さて、私はクロムヘッドレスブラウザに切り替えました。私はそれに切り替えた後、私の最初の仕事は、Webページ内のすべてのリンクを取得することです。しかし、すべてのリンクを取得するわけではありません。私はそれがページの読み込みに問題があると思ったので、各ページのタイムアウトを 'driver.set_page_load_timeout(45)'に設定しました。まだ動かない!同じコードがfirefoxとchromeブラウザで動作していましたが、ヘッドレスバージョンのchromeに切り替わったときは動作しませんでした。 –

+0

管理者は何らかの変更を加えておく必要があります。プロキシを使用し、プロキシを使用せずに通常のデスクトップにプロキシをロードする必要があります。 – EM28

+0

はい。当面はクロムブラウザが私の仕事でした! –

関連する問題