Python selenium sets chrome browser to keep login mode

 Usually we call the original browser. When we want to call the website after logging in, we have to log in and require a verification code, which is more troublesome. Use the following method to directly load the cookie stored in the browser after you log in. Login directly to the page after login)

# -*- coding:utf-8 -*-
from selenium import webdriver
import requests, time, json, re
from datetime import datetime, timedelta
from time import sleep
from lxml import etree
import socket
from hashlib import sha1
import hashlib


class Wish(object):
    # def __init__(self):

    def get_data(self):
        """获取cookie"""
        option = webdriver.ChromeOptions()
        option.add_argument(r"user-data-dir=C:\Users\Administrator\AppData\Local\Google\Chrome\User Data")    # 浏览器路径
        option.add_argument("blink-settings=imagesEnabled=false")    # 不加载图片

        # 初始化driver
        driver = webdriver.Chrome(options=option)

   

    def run(self):
        self.get_data()

if __name__ == '__main__':
    fps = Wish()
    fps.run()
options.AddArgument("--start-maximized")  # 开始最大化
options.AddArguments("--test-type")
options.AddArgument("--ignore-certificate-errors")  # 忽略证书错误

options.AddArgument("--disable-popup-blocking")  # 禁用弹出拦截
options.AddArgument("no-sandbox")  # 取消沙盒模式
options.AddArgument("no-default-browser-check")  # 禁止默认浏览器检查
options.AddArgument("about:histograms")
options.AddArgument("about:cache")

options.AddArgument("disable-extensions")  # 禁用扩展
options.AddArgument("disable-glsl-translator")  # 禁用GLSL翻译

options.AddArgument("disable-translate")  # 禁用翻译
options.AddArgument("--disable-gpu")  # 谷歌文档提到需要加上这个属性来规避bug
options.AddArgument("--disable-dev-shm-usage")
options.AddArgument("--hide-scrollbars")  # 隐藏滚动条, 应对一些特殊页面
options.AddArgument("blink-settings=imagesEnabled=false")  # 不加载图片, 提升速度

 Browser path configuration (generally the same)

 

 

Guess you like

Origin blog.csdn.net/weixin_43407092/article/details/97128833