无头模式,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

 

posted @ 2020-05-31 17:14  快乐的平头哥  阅读(347)  评论(0编辑  收藏  举报