Centos 在 Selenium 使用中的异常:chrome not reachable

在使用 Selenium 进行数据处理的过程中,发现了一些问题:

selenium.common.exceptions.WebDriverException: Message: chrome not reachable

 WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist

首先确认我们的 ChromeDriver 和已经安装的 Chromium 的版本匹配没有问题

chromium-browser --version
Chromium 90.0.4430.212 Fedora Project
../../driver/chromedriver --version
ChromeDriver 89.0.4389.23 (61b08ee2c50024bab004e48d2b1b083cdbdac579-refs/branch-heads/4389@{#294})

但是,之后发现问题依然存在。

经历了大量的调查,应该是上次使用 webdriver 的时候,没有关闭浏览器,所以

[root@iz8vb7tuq6sw9mx44vk7p6z ~]# ps aux | grep Chrome
root     18561  0.0  0.0 112812   976 pts/5    R+   08:26   0:00 grep --color=auto Chrome
scrapy   19401  0.0  1.7 34313044 17356 pts/2  Sl   Nov02   0:12 /usr/bin/chromium-browser --enable-plugins --enable-extensions --enable-user-scripts --enable-printing --enable-gpu-rasterization --enable-sync --auto-ssl-client-auth --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-automation --enable-blink-features=ShadowDOMV0 --enable-logging --headless --log-level=0 --no-first-run --no-service-autorun --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.com.google.Chrome.bV7kKM data:,
scrapy   19671  0.0  1.3 34300716 13676 pts/2  Sl   Nov02   0:11 /usr/bin/chromium-browser --enable-plugins --enable-extensions --enable-user-scripts --enable-printing --enable-gpu-rasterization --enable-sync --auto-ssl-client-auth --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-automation --enable-blink-features=ShadowDOMV0 --enable-logging --headless --log-level=0 --no-first-run --no-service-autorun --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.com.google.Chrome.nm1tQ1 data:,
scrapy   31991  0.0  1.3 34300716 13328 pts/2  Sl   Nov02   0:10 /usr/bin/chromium-browser --enable-plugins --enable-extensions --enable-user-scripts --enable-printing --enable-gpu-rasterization --enable-sync --auto-ssl-client-auth --disable-background-networking --disable-client-side-phishing-detection --disable-default-apps --disable-dev-shm-usage --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-automation --enable-blink-features=ShadowDOMV0 --enable-logging --headless --log-level=0 --no-first-run --no-sandbox --no-service-autorun --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir=/tmp/.com.google.Chrome.E71n9Z data:,

这里发现我们有3个 chromium 浏览器在运行,所以我们找到他们的 PID 并将他们一一关闭。

kill -9 PID

重新打开代码,就没有问题了

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果在 CentOS 系统使用 `cgcreate` 命令时提示 `-bash: cgcreate: command not found`,说明 cgroup 工具没有被安装或者没有被正确配置。您可以按照以下步骤进行修复: 1. 安装 cgroup 工具 使用以下命令安装 cgroup 工具: ``` sudo yum install libcgroup-tools ``` 2. 启用 cgroups 在启动时,需要使用 `cgroup_enable=memory swapaccount=1` 内核参数启用 cgroups。您可以按照以下步骤进行配置: - 编辑 `/etc/default/grub` 文件: ``` sudo nano /etc/default/grub ``` - 修改 `GRUB_CMDLINE_LINUX` 行,添加 `cgroup_enable=memory swapaccount=1` 参数: ``` GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1" ``` - 更新 GRUB 配置: ``` sudo grub2-mkconfig -o /boot/grub2/grub.cfg ``` - 重启系统: ``` sudo reboot ``` 3. 检查 cgroup 配置 检查 cgroup 是否正常工作,使用以下命令: ``` sudo systemctl status cgconfig ``` 如果 cgroup 配置正常工作,您应该会看到类似以下输出: ``` cgconfig.service - Control Group configuration service Loaded: loaded (/usr/lib/systemd/system/cgconfig.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2021-10-08 14:37:16 UTC; 2h 13min ago Main PID: 605 (cgconfigparser) Tasks: 1 Memory: 4.7M CPU: 16ms CGroup: /system.slice/cgconfig.service └─605 /usr/sbin/cgconfigparser -l /etc/cgconfig.conf -s 1660 Oct 08 14:37:16 centos cgconfigparser[605]: mount point /sys/fs/cgroup/unified not found or mount point not mounted Oct 08 14:37:16 centos systemd[1]: Started Control Group configuration service. ``` 如果提示未找到 `cgconfig` 或者 `cgconfigparser`,请尝试重新安装 cgroup 工具。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值