• web selenium 中webdriver的option


    options.add_argument(‘headless’) # 无头模式
    options.add_argument(‘window-size={}x{}’.format(width, height)) # 直接配置大小和set_window_size一样
    options.add_argument(‘disable-gpu’) # 禁用GPU加速
    options.add_argument(‘proxy-server={}’.format(self.proxy_server)) # 配置代理
    options.add_argument(’–no-sandbox’) # 沙盒模式运行
    options.add_argument(’–disable-setuid-sandbox’) # 禁用沙盒
    options.add_argument(’–disable-dev-shm-usage’) # 大量渲染时候写入/tmp而非/dev/shm
    options.add_argument(’–user-data-dir={profile_path}’.format(profile_path)) # 用户数据存入指定文件
    options.add_argument('no-default-browser-check) # 不做浏览器默认检查
    options.add_argument("–disable-popup-blocking") # 允许弹窗
    options.add_argument("–disable-extensions") # 禁用扩展


    options.add_argument("–ignore-certificate-errors") # 忽略不信任证书
    options.add_argument("–no-first-run") # 初始化时为空白页面
    options.add_argument(’–start-maximized’) # 最大化启动
    options.add_argument(’–disable-notifications’) # 禁用通知警告
    options.add_argument(’–enable-automation’) # 通知(通知用户其浏览器正由自动化测试控制)
    options.add_argument(’–disable-xss-auditor’) # 禁止xss防护
    options.add_argument(’–disable-web-security’) # 关闭安全策略
    options.add_argument(’–allow-running-insecure-content’) # 允许运行不安全的内容
    options.add_argument(’–disable-webgl’) # 禁用webgl
    options.add_argument(’–homedir={}’) # 指定主目录存放位置
    options.add_argument(’–disk-cache-dir={临时文件目录}’) # 指定临时文件目录
    options.add_argument(‘disable-cache’) # 禁用缓存
    options.add_argument(‘excludeSwitches’, [‘enable-automation’]) # 开发者模式

    常用的几个设置

     1 from selenium.webdriver.chrome.options import Options
     2 from selenium import webdriver
     3 chrome_options = Options()
     4 #加上下面两行,解决报错
     5 chrome_options.add_argument('--no-sandbox')
     6 chrome_options.add_argument('--disable-dev-shm-usage')
     7 chrome_options.add_argument('window-size=1920x3000') #指定浏览器分辨率
     8 chrome_options.add_argument('--disable-gpu') #谷歌文档提到需要加上这个属性来规避bug
     9 chrome_options.add_argument('--hide-scrollbars') #隐藏滚动条, 应对一些特殊页面
    10 chrome_options.add_argument('blink-settings=imagesEnabled=false') #不加载图片, 提升速度
    11 chrome_options.add_argument('--headless') #浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败
    12 # chrome_options.binary_location = r"C:Program Files (x86)GoogleChromeApplicationchrome.exe" #手动指定使用的浏览器位置
    13 
    14 
    15 driver=webdriver.Chrome(chrome_options=chrome_options)#executable_path驱动路径
    16 driver.get('http://www.baidu.com')
    17 print(driver.page_source)


    ————————————————
    版权声明:本文为CSDN博主「四个现代化」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/qq254271304/article/details/105766653

  • 相关阅读:
    [原创] Laravel 启动流程
    修改电脑的TTL返回值
    Apache启动错误解决方法
    RemodelanyWhere11.0.2673版本下载
    函数指针
    指针与数组
    青蛙跳台阶
    旋转数组的最小数字
    对大量人的年龄排序
    泛型算法一
  • 原文地址:https://www.cnblogs.com/x991788x/p/15113430.html
Copyright © 2020-2023  润新知