selenium调试本地浏览器

我直接说步骤

  1. 找到你的chrome.exe
  2. 终端执行chrome.exe完整路径 --remote-debugging-port=9222 --user-data-dir="自定义用户信息文件夹路径"
    例如我的就是G:\BX-UK\DE-002\Chrome.exe --remote-debugging-port=9222 --user-data-dir="G:\BX-UK\DE-002\Data\User Data" 敲完会出来一个浏览器
  3. python 执行
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
driver = webdriver.Chrome( options=chrome_options,executable_path='./chromedriver.exe')
driver.get('https://www.baidu.com')

即可调试浏览器
注意chromedriver版本要跟chrome对应
这种方法适用于完整版本chrome和便携版chrome,极大提高自动化开发效率。

猜你喜欢

转载自blog.csdn.net/A_I_H_L/article/details/121408979