g1879 / DrissionPage

Python based web automation tool. Powerful and elegant.
https://DrissionPage.cn/
BSD 3-Clause "New" or "Revised" License
8.15k stars 776 forks source link

Mac 使用 Edge 浏览器使用 use_system_user_path() 会卡死 #308

Open ChaXxl opened 3 months ago

ChaXxl commented 3 months ago
from DrissionPage import ChromiumPage, ChromiumOptions

co = ChromiumOptions()

path = '/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge'
co.set_browser_path(path)
co.use_system_user_path()
print(co.user_data_path)

page = ChromiumPage(addr_or_opts=co)

url = 'https://www.baidu.com/'
page.get(url)


执行后输出:

None
Traceback (most recent call last):
  File "/Users/xxl/Code/Python/CrawlBoss/main.py", line 10, in <module>
    page = ChromiumPage(addr_or_opts=co)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.12/site-packages/DrissionPage/_pages/chromium_page.py", line 38, in __new__
    is_exist, browser_id = run_browser(opt)
                           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.12/site-packages/DrissionPage/_pages/chromium_page.py", line 317, in run_browser
    is_exist = connect_browser(chromium_options)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.12/site-packages/DrissionPage/_functions/browser.py", line 56, in connect_browser
    test_connect(ip, port)
  File "/opt/homebrew/Caskroom/miniconda/base/lib/python3.12/site-packages/DrissionPage/_functions/browser.py", line 217, in test_connect
    raise BrowserConnectError(f'\n{ip}:{port}浏览器无法链接。\n请确认:\n1、该端口为浏览器\n'
DrissionPage.errors.BrowserConnectError: 
127.0.0.1:9222浏览器无法链接。
请确认:
1、该端口为浏览器
2、已添加'--remote-debugging-port=9222'启动项
3、用户文件夹没有和已打开的浏览器冲突
4、如为无界面系统,请添加'--headless=new'参数
5、如果是Linux系统,可能还要添加'--no-sandbox'启动参数
可使用ChromiumOptions设置端口和用户文件夹路径
MeoMeo0 commented 3 months ago
    options = ChromiumOptions()
    path = r'/usr/bin/google-chrome'
    ChromiumOptions().set_browser_path(path).save()
    arguments = [
        "-no-sandbox",
        "-no-first-run",
        "-force-color-profile=srgb",
        "-metrics-recording-only",
        "-password-store=basic",
        "-use-mock-keychain",
        "-export-tagged-pdf",
        "-no-default-browser-check",
        "-disable-background-mode",
        "-enable-features=NetworkService,NetworkServiceInProcess,LoadCryptoTokenExtension,PermuteTLSExtensions",
        "-disable-features=FlashDeprecationWarning,EnablePasswordsAccountStorage",
        "-deny-permission-prompts",
        "-disable-gpu",
        "-accept-lang=en-US",
        "-remote-debugging-port=9222"
    ]
    Hope this helps you out !