admin管理员组

文章数量:1529449

文章目录

配置chrome

连接浏览器


 

配置chrome

open -e ~/.zshrc
  • 在结尾添加:
export PATH="/Applications/Google Chrome.app/Contents/MacOS:$PATH"
  • 保存后退出,然后启动一个窗口:
Google\ Chrome --remote-debugging-port=19222 --user-data-dir="~/ChromeProfile"
  • 其中Google\ Chrome为一个命令,把chrome添加到环境变量就可以看到了

这里是指定chrome的端口19222,这段代码执行结束后也不会退出driver,我们使用:

lsof -i:19222
  • 就可以看到39222端口有监听状态的Google

连接浏览器

from selenium import webdriver

options = webdriver.ChromeOptions()

options.add_experimental_option("debuggerAddress", "127.0.0.1:19222")
driver = webdriver.Chrome(options=options)
driver.get('https://www.baidu')
  • 参考网站:https://cosmocode.io/how-to-connect-selenium-to-an-existing-browser-that-was-opened-manually/#2-step-1-launch-browser-with-custom-flags

本文标签: 开新浏览器Macseleniumchrome