• 亲测可用!!!Centos7安装chrome+chromedriver以便实现selenium自动化详细教程


    网上很多教程都是在线安装chrome,这样安装了最新稳定的chrome,可惜我遇到chromdriver的版本跟上 chrome,为了早日实现在centos服务selenium自动化,不可能去等待 chromdriver 更新,只能 chrome进行降版本来离线安装。花了几个小时找资源,终于找到一个可用的:

    安装chrome

    一、下载安装包链接: https://pan.baidu.com/s/1ScyMB54eoFfGXq7-RapsdA 提取码: amnp

    二、安装流程

    rpm -ivh vulkan-filesystem-1.1.97.0-1.el7.norch.rpm

    rpm -ivh vulkan-1.1.97.0-1.el7.x86_64.rpm

    rpm -ivh liberation-narrow-fonts-1.07.2-16.el7.noarch.rpm

    rpm -ivh liberation-fonts-1.07.2-16.el7.noarch.rpm

    rpm -i google-chrome-stable-current_x86_x64.rpm

    chromedriver安装

    chromedriver下载
    在https://npm.taobao.org/mirrors/chromedriver/中下载对应版本的chromedriver,上面的chrome对应下面这个版本的:

    https://cdn.npmmirror.com/binaries/chromedriver/103.0.5060.134/chromedriver_linux64.zip

    解压软件:可在windows下下载, 解压后再转移过去,或unzip chromedriver_linux64.zip
    将软件移至对应目录下(很重要)
    mv chromedriver /usr/bin/

    赋权限
    chmod +x /usr/bin/chromedriver

    验证安装完成
    直接输入chromedriver

    编写python测试chrome以及驱动是否能够正常运行

    测试代码test_google.py

    1. from selenium import webdriver
    2. from selenium.webdriver.chrome.options import Options
    3. # 创建 ChromeOptions 实例,启用无头模式
    4. chrome_options = Options()
    5. chrome_options.add_argument('--headless')
    6. chrome_options.add_argument('--no-sandbox')
    7. chrome_options.add_argument('--disable-dev-shm-usage')
    8. # 指定 ChromeDriver 的路径(根据实际情况修改)
    9. chrome_driver_path = '/usr/bin/chromedriver'
    10. # 创建 Chrome WebDriver 实例
    11. driver = webdriver.Chrome(executable_path=chrome_driver_path, options=chrome_options)
    12. # 打开网页
    13. driver.get('https://www.google.com')
    14. # 输出网页标题
    15. print('Page title:', driver.title)
    16. # 关闭浏览器
    17. driver.quit()

    运行成功的结果

    python test_google.py

    /usr/path/test_google.py:13: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
    driver = webdriver.Chrome(executable_path=chrome_driver_path, options=chrome_options)
    Page title: Google

  • 相关阅读:
    设计模式18—— 迭代器模式
    寒气笼罩中的一线暖冬
    InFusion:通过从扩散先验学习深度补全来进行图像 3D 高斯修复
    __ manifest __.py文件详解
    Java面试题目大汇总(附参考答案)
    Android修行手册 - 一文全了解Kotlin几种静态变量、函数实现的那些事
    Python基础语法入门
    记录一次官网访问很慢的情况
    数字金融场景下数据安全建设方案
    Dubbo基于注解方式的配置
  • 原文地址:https://blog.csdn.net/linweidong/article/details/132912561