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"

sdf

然后 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")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值