zoukankan      html  css  js  c++  java
  • web自动化:IE11运行Python+selenium程序

    from selenium import webdriver  # 运行此脚本前必须按要求修改注册表
    '''
    [HKEY_CURRENT_USERSoftwareMicrosoftInternet ExplorerMainFeatureControlFEATURE_HTTP_USERNAME_PASSWORD_DISABLE]
    "iexplore.exe"=dword:00000000
    针对IE11,需要修改注册表。如果是32位的windows,key值为HKEY_LOCAL_MACHINESOFTWAREMicrosoftInternetExplorerMainFeatureControlFEATURE_BFCACHE
    ,如果是64位的windows,key值为HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftInternetExplorerMainFeatureControlFEATURE_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)
    

      

  • 相关阅读:
    java mail 读取邮件列表,
    java itext 报错 com.itextpdf.text.DocumentException: Font 'STSong-Light' with 'UniGB-UCS2-H'
    shiro 标签
    idea maven 创建webapp项目没有src目录
    is not allowed to connect to this MySQL server解决办法
    mybatis 插入数据并返回主键值
    idea15 生成mybatis代码
    android 打开新窗口
    Java开发笔记(八十四)文件与目录的管理
    Java开发笔记(八十三)利用注解技术检查空指针
  • 原文地址:https://www.cnblogs.com/jieliu8080/p/10511395.html
Copyright © 2011-2022 走看看