栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

selenium: chrom debug模式,进行自动操作;复用cookies;免密码重新登陆

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

selenium: chrom debug模式,进行自动操作;复用cookies;免密码重新登陆

先 用命令行 开启 debug 模式的 chrome
/Applications/Google Chrome.app/Contents/MacOS/Google Chrome --remote-debugging-port=9222 --user-data-dir="/Users/paul/Desktop/seleniumProfile"

然后 py selenium代码
#! /usr/bin/env python3
# -*- coding: UTF-8 -*-

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time

DRIVER_PATH = "/Users/paul/code/myEnvironment/chromedriver" # /Users/paul/code/myEnvironment/chromedriver # ./driver/chromedriver.exe

class Driver:
	def __init__(self):
		# 初始化驱动
		self.driver = None
		self._init_driver()

	def _init_driver(self):
		if self.driver:
			return
		option = webdriver.ChromeOptions()
		# 这一句重要:用于连接我们 debug 模式的 chrome
		option.add_experimental_option('debugerAddress', '127.0.0.1:9222')
		option.add_argument("--disable-blink-features")
		option.add_argument("--disable-blink-features=AutomationControlled")

		self.driver = webdriver.Chrome(options=option, executable_path=DRIVER_PATH) #  /Users/paul/code/myEnvironment/chromedriver

	def doSomething(self, content):
		print("sending start")
		# ...
		self.driver.find_element_by_css_selector(SubmitButton).click()
		print("all done")

if __name__ == '__main__':
	print("in main")
	work = Driver()
	work.doSomething("test from slelenium #test")
	print("end main")
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/283828.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号