zoukankan      html  css  js  c++  java
  • 无头模式,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
  • 相关阅读:
    elasticsearch的基本用法
    JavaScript实现拖拽预览,AJAX小文件上传
    php四排序-选择排序
    php四排序-冒泡排序
    centos6.5编译安装lamp开发环境
    centos7.2 yum安装lamp环境
    chrome升级54以后,显示Adobe Flash Player 因过期而遭到阻止
    chrome45以后的版本安装lodop后,仍提示未安装解决
    APACHE重写去除入口文件index.php
    PHP之factory
  • 原文地址:https://www.cnblogs.com/chevron123/p/13019894.html
Copyright © 2011-2022 走看看