当前位置:首页 > Python笔记 > 正文内容

用Python的selenium利用chrome的debugger模式操控浏览器


1 cmd命令开启Chrome的debugger模式

C:\Users\Administrator\AppData\Local\Google\Chrome\Application>chrome.exe --remo

te-debugging-port=9222 --user-data-dir="D:\Desktop\item\chromtest\Chrome\Applica

tion\test"

2 Python代码接管浏览器,代码如下:

import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

options=Options()
options.add_experimental_option('debuggerAddress','127.0.0.1:9222')
bro=webdriver.Chrome(options=options)
time.sleep(3)
yuanma=bro.page_source
print(yuanma)

input=bro.find_element(By.ID,'search-input')
input.send_keys('ssss')
input.send_keys('招聘')
time.sleep(1)
bro.find_element(By.CLASS_NAME,'input-button').click()
time.sleep(3333)


微信截图_20240228205258.png

发表评论

(必填)
(必填)
(选填)

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

最新文章

最新留言

标签列表