0


Python使用selenium控制已经打开的浏览器

1、打开chrome

①cmd----进入chrome.exe目录下

chrome.exe --remote-debugging-port=9527 --user-data-dir=“D:\selenium\AutomationProfile”

②直接进入cmd

start chrome --remote-debugging-port=9527 --user-data-dir="D:\selenium\AutomationProfile"

import os
os.popen('start chrome --remote-debugging-port=9527 --user-data-dir="D:\selenium\AutomationProfile"')

2、代码

options = Options()
options.add_experimental_option("debuggerAddress", "127.0.0.1:9527")
driver = webdriver.Chrome(options=options)
print(driver.title)
url = "xxxxxxxxx"

driver.get(url)
time.sleep(3)

注意!!!

端口号需要一致

使用jupyter可以基于当前界面操作(一大段程序需要提前设置好)


本文转载自: https://blog.csdn.net/m0_52029912/article/details/138310457
版权归原作者 土星沉迷学习的园子 所有, 如有侵权,请联系我们删除。

“Python使用selenium控制已经打开的浏览器”的评论:

还没有评论