zoukankan      html  css  js  c++  java
  • selenium常用配置

    from selenium import webdriver
    import time
    from selenium.webdriver.chrome.options import Options  # 配置的包
    
    path = 'chromedriver.exe'
    
    # 配置相关
    chrome_options = Options()  # 可以理解为配置对象
    # 1. 配置不加载图片
    # prefs = {"profile.managed_default_content_settings.images": 2}
    # chrome_options.add_experimental_option("prefs", prefs)
    
    # 2. 无界面
    # chrome_options.add_argument('--headless')
    # chrome_options.add_argument('--disable-gpu')
    
    # 3. 移动端配置
    # WIDTH = 600
    # HEIGHT = 800
    # PIXEL_RATIO = 3.0
    # UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'
    # mobileEmulation = {"deviceMetrics": {"width": WIDTH, "height": HEIGHT, "pixelRatio": PIXEL_RATIO}, "userAgent": UA}
    # chrome_options.add_experimental_option('mobileEmulation', mobileEmulation)
    
    # 4. 操作已打开的浏览器
    # chrome.exe --remote-debugging-port=9222 --user-data-dir="C:selenumAutomationProfile"
    chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
    
    browser = webdriver.Chrome(path, options=chrome_options)
    browser.get('http://www.netbian.com/')
    time.sleep(15)
    browser.quit()
    人生苦短,慢慢潇洒。 www.zwnsyw.com
  • 相关阅读:
    我的友情链接
    我的友情链接
    以太坊:根据例子学习Solidity
    以太坊:安装Solidity编译器
    以太坊:入门智能合约
    以太坊:Solidity手册
    Web3 :Tech Stack Overview
    Web3 – The Decentralized Web
    去中心化金融项目汇总 Defi
    跨链技术汇总
  • 原文地址:https://www.cnblogs.com/zwnsyw/p/14656820.html
Copyright © 2011-2022 走看看