使用 Selenium/Python/Linux 从 Chrome 切换到 Chromium 时出现分段错误

Segmentation fault when switching from Chrome to Chromium with Selenium/Python/Linux

提问人:arno77 提问时间:4/12/2023 更新时间:4/12/2023 访问量:384

问:

我有一个使用 Selenium(无头)和 Chrome 作为底层浏览器的工作 Python 应用程序。切换到 Chromium 时,我遇到分段错误(libstdc++.so.6.0.25 中的错误 4)。不过,该应用程序可以继续工作。我不确定如何摆脱这些分段错误。

设置:

  • Oracle Linux 8(与 RHEL8/CENTOS8 兼容)
  • Python 3.9.13 中文文档
  • 硒 4.8.3
  • 铬 111.0.5563.146
  • Chrome驱动程序 111.0.5563.146

这是代码(已编辑):

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.expected_conditions import visibility_of_element_located
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions as EC
from datetime import datetime
from fake_useragent import UserAgent
import time

chromium_path = '/usr/bin/chromedriver'


options = Options()
options.add_argument("headless")
options.add_argument("--incognito")
options.add_argument("--nogpu")
options.add_argument("--disable-gpu")
options.add_argument("--no-sandbox")
options.add_argument("--enable-javascript")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_argument("--window-size=1920,1080")
options.binary_location = '/usr/bin/chromium-browser'

ua = UserAgent()
userAgent = ua.random

ser = Service(r"/usr/bin/chromedriver")

browser = webdriver.Chrome(service=ser, options=options)
# First Segfault
browser.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
browser.execute_cdp_cmd('Network.setUserAgentOverride', {"userAgent": userAgent})
# Second Segfault

分段故障示例:

[1282594.979885] chromium-browse[1222575]: segfault at 0 ip 00007f1f96690e38 sp 00007ffc29825c80 error 4 in libstdc++.so.6.0.25[7f1f965fc000+186000]

不知道如何解决此问题。非常感谢反馈。感谢您抽出时间接受采访。

python linux selenium-webdriver selenium-chromedriver chromium

评论

0赞 awado 7/6/2023
我可以在Raspberry Pi Zero上重现这一点,而它在Pi 3上运行。会不会是单一核心问题?

答: 暂无答案