You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多
文档控制台
免费开始使用

在Pydroid 3中使用Selenium加载Chrome失败,求解决方法

问题:Pydroid 3中Selenium无法启动浏览器,报错Unsupported platform/architecture combination: linux/aarch64

在Pydroid 3中使用Selenium时,模块及子模块可正常加载,但浏览器无法启动,报错信息如下:

Traceback (most recent call last):
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/selenium/webdriver/common/driver_finder.py", line 67, in _binary_paths
    output = SeleniumManager().binary_paths(self._to_args())             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/selenium/webdriver/common/selenium_manager.py", line 45, in binary_paths
    args = [str(self._get_binary())] + args
                ^^^^^^^^^^^^^^^^^^
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/selenium/webdriver/common/selenium_manager.py", line 83, in _get_binary
    raise WebDriverException(f"Unsupported platform/architecture combination: {sys.platform}/{arch}")
selenium.common.exceptions.WebDriverException: Message: Unsupported platform/architecture combination: linux/aarch64

引发后续异常:

Traceback (most recent call last):
  File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
    start(fakepyfile,mainpyfile)
  File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
    exec(open(mainpyfile).read(),  __main__.__dict__)
  File "<string>", line 5, in <module>
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 45, in __init__
    super().__init__(
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py", line 50, in __init__
    if finder.get_browser_path():
       ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/selenium/webdriver/common/driver_finder.py", line 47, in get_browser_path
    return self._binary_paths()["browser_path"]
           ^^^^^^^^^^^^^^^^^^^^
  File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.11/site-packages/selenium/webdriver/common/driver_finder.py", line 78, in _binary_paths
    raise NoSuchDriverException(msg) from err
selenium.common.exceptions.NoSuchDriverException: Message: Unable to obtain driver for chrome

解决方案

1. 手动适配aarch64架构的ChromeDriver

Selenium Manager暂不支持Android的aarch64架构,需手动下载对应版本的ChromeDriver:

  • 下载与手机Chrome版本匹配的aarch64架构ChromeDriver
  • 将文件放到Pydroid有权限访问的路径(比如内部存储的Download文件夹)
  • 初始化WebDriver时手动指定驱动路径:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

# 配置Chrome适配移动端环境
chrome_options = Options()
chrome_options.add_argument('--headless')  # 移动端推荐无界面模式
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')

# 替换为你的chromedriver实际路径
driver = webdriver.Chrome(executable_path='/storage/emulated/0/Download/chromedriver', options=chrome_options)

2. 改用Firefox GeckoDriver替代

Firefox的GeckoDriver对aarch64架构支持更友好:

  • 下载适配Android aarch64的GeckoDriver,确保与手机Firefox版本匹配
  • 手动指定驱动路径初始化:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options

firefox_options = Options()
firefox_options.add_argument('--headless')

# 替换为你的geckodriver实际路径
driver = webdriver.Firefox(executable_path='/storage/emulated/0/Download/geckodriver', options=firefox_options)

3. 降级Selenium版本

部分旧版本Selenium的驱动查找逻辑兼容性更强,可尝试降级到4.8.x版本:
在Pydroid终端执行:

pip install selenium==4.8.3

降级后手动指定驱动路径即可绕过Selenium Manager的架构校验。


内容的提问来源于stack exchange,提问作者Vidyaramanan

火山引擎 最新活动