web自動化:IE11運行Python+selenium程序


from selenium import webdriver  # 運行此腳本前必須按要求修改注冊表
'''
[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_HTTP_USERNAME_PASSWORD_DISABLE]
"iexplore.exe"=dword:00000000
針對IE11,需要修改注冊表。如果是32位的windows,key值為HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InternetExplorer\Main\FeatureControl\FEATURE_BFCACHE
,如果是64位的windows,key值為HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\InternetExplorer\Main\FeatureControl\FEATURE_BFCACHE
如果key值不存在,就添加。之后在key內部創建一個iexplorer.exe,DWORD類型,值為0'''

driver = webdriver.Ie()
driver.get("http://www.baidu.com")
#driver.get("http://admin:admin@10.82.21.145/")
需要下載與Python版本對應的webdriver
ie網頁縮放比例要為100%大小,同時要注意Internet選項->安全,里面的保護模式全部勾選或者全部關閉。
import win32api
import win32con

key = win32api.RegCreateKey(win32con.HKEY_CURRENT_USER,
                            'Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\ZoneMap\\Ranges\\Range10')
win32api.RegSetValueEx(key, ':Range', 0, win32con.REG_SZ, '10.82.21.190')
win32api.RegSetValueEx(key, 'http', 0, win32con.REG_DWORD, 2)
win32api.RegCloseKey(key)

# IE安全保護模式全部取消
key1 = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
                           'Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\1',
                           0, win32con.KEY_WRITE)
win32api.RegSetValueEx(key1, '2500', 0, win32con.REG_DWORD, 3)  # 最后一個參數中(3:關閉,0:開啟)
win32api.RegCloseKey(key1)

key2 = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
                           'Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\2',
                           0, win32con.KEY_WRITE)
win32api.RegSetValueEx(key2, '2500', 0, win32con.REG_DWORD, 3)
win32api.RegCloseKey(key2)

key3 = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
                           'Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\3',
                           0, win32con.KEY_WRITE)
win32api.RegSetValueEx(key3, '2500', 0, win32con.REG_DWORD, 3)
win32api.RegCloseKey(key3)

key4 = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
                           'Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Zones\\4',
                           0, win32con.KEY_WRITE)
win32api.RegSetValueEx(key4, '2500', 0, win32con.REG_DWORD, 3)
win32api.RegCloseKey(key4)

key5 = win32api.RegOpenKey(win32con.HKEY_CURRENT_USER,
                           'Software\\Microsoft\\Internet Explorer\\Zoom',
                           0, win32con.KEY_WRITE)
win32api.RegSetValueEx(key5, 'ZoomFactor', 0, win32con.REG_DWORD, 100000)
win32api.RegCloseKey(key5)

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM