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)

  

posted @ 2019-03-11 16:21  autotest_man  阅读(1280)  评论(0编辑  收藏  举报