我正在尝试设置 Google Chrome、Firefox 以及 Selenium WebDriver 来进行网页抓取。工具版本-
- Google Chrome 89.0.4389.90
- Mozilla Firefox 87.0
- geckodriver 0.29.0 (cf6956a5ec8e 2021-01-14 10:31 +0200)
- ChromeDriver 89.0.4389.23(61b08ee2c50024bab004e48d2b1b083cdbdac579-refs/branch-heads/4389@{#294})
- 蟒蛇3.8
工具目录
- usr/bin/google-chrome
- usr/bin/firefox
- /usr/bin/geckodriver
- usr/local/bin/chromedriver
Firefox 设置的错误响应
[Mon Apr 05 12:00:41.455935 2021] [wsgi:error] [pid 166126:tid 140071119365888] [client 27.60.45.7:39715] self._execute_child(args, executable, preexec_fn, close_fds,, referer: http://example.com/scrapfbmoz
[Mon Apr 05 12:00:41.455941 2021] [wsgi:error] [pid 166126:tid 140071119365888] [client 27.60.45.7:39715] File "/usr/lib/python3.8/subprocess.py", line 1702, in _execute_child, referer: http://example.com/scrapfbmoz
[Mon Apr 05 12:00:41.455944 2021] [wsgi:error] [pid 166126:tid 140071119365888] [client 27.60.45.7:39715] raise child_exception_type(errno_num, err_msg, err_filename), referer: http://example.com/scrapfbmoz
[Mon Apr 05 12:00:41.455964 2021] [wsgi:error] [pid 166126:tid 140071119365888] [client 27.60.45.7:39715] PermissionError: [Errno 13] Permission denied: '/usr/local/bin/firefox', referer: http://example.com/scrapfbmoz
Chrome 设置错误响应
[Mon Apr 05 10:30:31.315019 2021] [wsgi:error] [pid 161147:tid 140070870828800] [client 106.205.46.151:9653] selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally., referer: http://example.com/scrapfb
[Mon Apr 05 10:30:31.315023 2021] [wsgi:error] [pid 161147:tid 140070870828800] [client 106.205.46.151:9653] (unknown error: DevToolsActivePort file doesn't exist), referer: http://example.com/scrapfb
[Mon Apr 05 10:30:31.315027 2021] [wsgi:error] [pid 161147:tid 140070870828800] [client 106.205.46.151:9653] (The process started from chrome location usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.), referer:
答案1
我将尝试回答您的问题,而不是询问您这与 Ubuntu 有何关系:
对于您的 Firefox 问题,错误信息为:PermissionDenied: /usr/local/bin/firefox
。这意味着无论此进程以何种用户身份运行,您都没有正确的权限来执行此目录中的任何操作。要解决此问题,您有两个选择:您可以以 root 或提升权限(最好是 sudo,而不仅仅是登录 root 帐户)运行该进程,或者您可以使用 或 更改它指向的目录或 ELF 的权限chmod
。chown
请注意,如果您按照此操作,您将需要sudo
.sudo chmod -R 644 /usr/local/bin/firefox
或sudo chmod -R 755 /usr/local/bin/firefox
才能sudo chown <whatever user you want> -R /usr/local/bin/firefox
工作。
644:所有者可以读取和写入,其他所有人都只能读取。755:所有者可以读取、写入和执行,但其他所有人都可以读取和执行。
如果我犯了任何错误,请纠正我!
至于您的 Selenium 问题,这似乎是一个非常常见的问题。我建议您升级您的 Chrome、webdriver 和其他任何东西以排除这些问题。StackOverflow 上有一个类似的问题:https://stackoverflow.com/questions/50642308/webdriverexception-unknown-error-devtoolsactiveport-file-doesnt-exist-while-t