zoukankan      html  css  js  c++  java
  • selenium 定制启动chrome的参数

    selenium 定制启动chrome的参数
    设置代理. 禁止图片加载 修改ua
    https://blog.csdn.net/vinson0526/article/details/51850929

    1.配置chrome以手机模拟器
    https://blog.csdn.net/u013948858/article/details/81123951

    from selenium import webdriver
     
    mobile_emulation = { "deviceName": "Nexus 5" }
     
    chrome_options = webdriver.ChromeOptions()
     
    chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) # 这里看清楚了,不是add_argument
     
    driver = webdriver.Remote(command_executor='http://127.0.0.1:4444/wd/hub',desired_capabilities = chrome_options.to_capabilities())
    
    #====
    from selenium import webdriver
     
    from selenium.webdriver.chrome.options import Options
     
    mobile_emulation = {
     
       "deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 },
     
       "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19" }
     
    chrome_options = Options()
     
    chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) # 这里看清楚了,不是add_argument
     
    driver = webdriver.Chrome(chrome_options = chrome_options) # 这里的chrome_options 建议都使用 desired_capabilities ,应为在Grid分布式中比较方便
     
    

    2.取消显示 收到自动化软件的控制 / 静默方式运行

    from selenium import webdriver
    
    # 加启动配置
    option = webdriver.ChromeOptions()
    option.add_argument('disable-infobars')
    #return webdriver.Chrome(chrome_options = option,desired_capabilities = None)
    
    # 打开chrome浏览器
    driver = webdriver.Chrome(chrome_options=option)
    driver.get("https://www.baidu.com") 
    
    from selenium import webdriver
    
    # 加启动配置
    option = webdriver.ChromeOptions()
    option.add_argument('headless')
    
    # 打开chrome浏览器
    driver = webdriver.Chrome(chrome_options=option)
    driver.get("https://www.baidu.com")
    
  • 相关阅读:
    uoj#214. 【UNR #1】合唱队形
    「集训队作业2018」复读机
    WPF进阶技巧和实战01-小技巧
    03 依赖注入--01控制反转、IoC模式
    01 ASP.NET Core 3 启动过程(一)
    05-IdentityServer4
    IdentityServer4系列[6]授权码模式
    04-授权策略
    03-Jwt在.netcore中的实现
    02-token
  • 原文地址:https://www.cnblogs.com/lovesKey/p/10974478.html
Copyright © 2011-2022 走看看