• 无头模式,Windows和Linux


    ----windows

    from selenium  import webdriver

    from selenium .webdriver.common.by import By

    import ttime

    chrome_options =webdriver.ChromeOptions()

    chrome_options.add_argument('--headless')

    chrome_options.add_argument('--disable-gpu')

    chrome_options.add_argument('--window-size =1920,1050')

    driver =webdriver.Chrome(options = chrome_options)

     ----------------------------------------------------------

    linux 

    # cd  /etc/yum.repos.d/

    # vi google-chrome.repo

    [google-chrome]
    name=google-chrome
    baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
    enabled=1
    gpgcheck=1
    gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
    ————————————————
    #yum -y install google-chrome-stable --nogpgcheck
    查看版本
    # /usr/bin/google-chrome -version
    
    chromedriver 地址 http://chromedriver.storage.googleapis.com/index.html?path=83.0.4103.39/
    
    
    
    原文链接:https://blog.csdn.net/wudaoshihun/article/details/82948013

    给驱动赋权

    #mv chromedriver /usr/bin/chromedirver

    # chmod +x chromedriver

    #pip3 install selenium 

    安装 python3 https://www.cnblogs.com/scajy/p/11262622.html

    进入我的python就脚本文件

    进入 目录 
    software]# vi study.py
     # -*- coding :utf-8 -*-
    # @Author:kuai le de ping tou ge
    
    from selenium.webdriver.common.by import By
    from selenium import webdriver
    import time
    import os
    
    google_location = '/usr/bin/google-chrome'
    driver_location = '/usr/bin/chromedriver'
    
    
    options = webdriver.ChromeOptions()
    options.binary_location = google_location
    options.add_argument('--no-sandbox')
    options.add_argument('--headless')
    options.add_argument('--disable-gpu')
    options.add_argument('--window-size=1920,1050')
    
    chromedriver = driver_location
    #os.envir["webdriver.chrome.driver"] = chromedriver
    
    driver = webdriver.Chrome(chrome_options=options,executable_path=chromedriver)
    
    driver.get('http://test-agent.hczypay.com')
    driver.get_screenshot_as_file('login.png')
    
    driver.close()

    software]# python3 study.py

    DeprecationWarning: use options instead of chrome_options 警告问题的解决 

    警告问题见url
    https://blog.csdn.net/xpt211314/article/details/103301344
  • 相关阅读:
    设计模式总结
    JWT、OAUTH2与SSO资料补充
    dajie项目的坑
    fw-cloud-framework项目配置、启动问题
    Shiro源码分析
    (转)JPA & Restful
    Spring Boot以War包启动
    (转)Spring & SpringMVC学习
    MySQL的数据类型(二)
    MySQL的数据类型(一)
  • 原文地址:https://www.cnblogs.com/chevron123/p/13019894.html
Copyright © 2020-2023  润新知