python+seleium 控制已打开的谷歌浏览器

1.谷歌浏览器目标位置 添加端口: --remote-debugging-port=9222

 

 

 2.启动谷歌浏览器driver

#!/bin/env python
#-*- coding:utf-8 -*-
from selenium import webdriver
import pyperclip
import time
import random
import numpy as np
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.debugger_address="127.0.0.1:9222"
chrome_driver = "C:\Python36\chromedriver.exe"#driver路径
driver = webdriver.Chrome(chrome_driver,chrome_options=chrome_options)

print(driver.title)

  

3.如果报错找不到端口,检查driver版本是否与浏览器版本一直

3.1检查任务管理器进程,需结束所有chrome进程后重进

posted @ 2022-02-23 14:37  究极不吃香菜  阅读(594)  评论(0编辑  收藏  举报