2017-08-31 109 views
0
from selenium import webdriver 
import csv 
import time 

url_results=[] 
driver_ie = webdriver.Ie('C:\\Users\\aviv\\Desktop\\IEDriverServer') 

with open ('C:\\Users\\aviv\\Desktop\\urlspart.txt','r') as d: 
    urls= d.read().splitlines() 

    for i,url in enumerate(urls): 

     try: 
      print "URL: " + url 
      driver_ie.get(url) 
      time.sleep(7) 
      current_url_ie = driver_ie.current_url 
      redirect_ie='No' 
      if current_url_ie == 'https://www.aviv.com': 
       redirect_ie ='Yes' 

     except Exception,e: 
      redirect_ie = 'error' 
      print e, Exception 



     writer.writerow([i,url,redirect_ie]) 
ofile.close() 

此代碼拋出異常並顯示消息:「Unable to get browser」。python中的硒webdriver - 無法獲取瀏覽器

我已經更改了Internet選項 - >安全並簽署了「啓用保護模式」, 但是錯誤仍然存​​在。

任何解決方案?

+0

你爲什麼要初始化'driver_ie'兩次? –

+0

我編輯它,這不是問題。 –

+0

您可以粘貼完整的錯誤堆棧跟蹤以進一步分析嗎? – DebanjanB

回答

0

僅適用於IE 11,您需要在目標計算機上設置註冊表項,以便驅動程序可以維護與創建的Internet Explorer實例的連接。

對於32位Windows安裝,您必須在註冊表編輯器中考查的重點是

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE 

對於64位Windows安裝中,關鍵是

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BFCACHE 

請注意FEATURE_BFCACHE子鍵可能存在也可能不存在,如果不存在則應該創建。重要說明:在此密鑰內部,創建一個名爲iexplore.exe的DWORD值,值爲0

http://heliumhq.com/docs/internet_explorer下載註冊表文件。

請參閱https://code.google.com/p/selenium/wiki/InternetExplorerDriver瞭解更多必需的IE配置步驟。

另請參考:

https://github.com/seleniumhq/selenium-google-code-issue-archive/issues/6511

希望它會幫助你:)

+0

謝謝,但我也試過了,錯誤依然存在。 –

0

可能是因爲在驅動程序路徑的終點缺少.exe文件。請按以下所示添加.exe。它可能適合你。

driver_ie = webdriver.Ie('C:\\Users\\aviv\\Desktop\\IEDriverServer.exe') 
相關問題