DEV Community

drake
drake

Posted on

Drissionpage连接本地已经打开的浏览器

from DrissionPage import Chromium, ChromiumOptions co = ChromiumOptions() # co.incognito() # 本地已经打开的浏览器端口号 # 你也可以不显式制定端口,其默认连接的就是9222端口 co.set_local_port(9222) browser = Chromium(co) # browser.clear_cache() browser.set.auto_handle_alert() # 标签页操作 tab = browser.latest_tab 
Enter fullscreen mode Exit fullscreen mode
  • 本地浏览器的打开方式
# Windows 示例 "C:\Program Files\Google\Chrome\Application\chrome.exe" --remote-debugging-port=9222 --user-data-dir="C:\temp\chrome_profile" # macOS 示例 /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222 --user-data-dir="/tmp/chrome_profile" # Linux 示例 google-chrome --remote-debugging-port=9222 --user-data-dir="/tmp/chrome_profile" 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)