树莓派aarch64架构debian系统安装无头浏览器 python selenium踩坑
·
首先
selenium版本不能用4.x.0,开始开发的时候用的4.16.0,docker安装的时候2024年8月默认版本是4.24.0,会报找不到驱动 或者 不支持 linux/aarch64 架构
selenium==3.8.0
安装 chromium、chromedriver、chromium-browser
sudo apt update
sudo apt install chromium
sudo apt install chromium-browser
#sudo apt install chromedriver # 没有资源,从安装成功的cm4树莓派上下载下来的14.7MB大小
# sudo mv chromedriver /usr/bin/chromedriver
# cd /usr/bin
# chmod 755 chromedriver
test.py
executable_path地址根据实际情况填写,我的树莓派默认是"/usr/bin/chromedriver"
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument("--headless") # 设置无头模式
chrome_options.add_argument("--disable-gpu") # 禁用GPU加速
chrome_options.add_argument("--no-sandbox") # 禁用沙箱模式
chrome_options.add_argument('--disable-features=VizDisplayCompositor')
driver = webdriver.Chrome(executable_path="/usr/bin/chromedriver", options=chrome_options)
driver.get(f"http://www.baidu.com") # 打开网页
print("标题:", driver.title)
print("当前url:", driver.current_url)
driver.quit() # 关闭浏览器
更多推荐
所有评论(0)