3
python | selenium 操纵已经打开的 chrome
source link: https://benpaodewoniu.github.io/2024/03/11/python200/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
python | selenium 操纵已经打开的 chrome
通过调试接口来操作已经打开的 chrome
。
chrome.exe --remote-debugging-port=9233 --user-data-dir="D:\chrome\1"
打开 chrome
。
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9233")
driver = webdriver.Chrome(options=options)
window_rect = driver.get_window_rect()
print("窗口左上角坐标:", window_rect["x"], window_rect["y"])
print("窗口右下角坐标:", window_rect["x"] + window_rect["width"], window_rect["y"] + window_rect["height"])
# 测试打印页面标题
print(driver.title)
ps: 我把 chromedriver.exe
放在同级目录中。
请我喝杯咖啡吧~
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK