python selenium 爬虫入门备忘

在Linux上使用Python Selenium和GoogleDriver进行自动化测试或网页爬取时,需要安装和配置几个关键组件。以下是详细的介绍和步骤:

安装Google Chrome浏览器我用的版本是96.0.4664.45-1 :

可以使用包管理工具如yum。

https://download.csdn.net/download/cheng_ji/90085155 可以在这里下载浏览器和驱动,已经为大家打包好了。

下载解压后安装

在CentOS上可以使用以下命令安装:

bash 复制代码
yum install google-chrome-stable-96.0.4664.45-1.x86_64.rpm

解压安装ChromeDriver:

bash 复制代码
unzip chromedriver_linux64\(1\).zip 
mv chromedriver /usr/bin/
chmod +x /usr/bin/chromedriver
chromedriver --version

ChromeDriver是用于与Google Chrome交互的驱动程序,必须安装。

安装Selenium:

使用pip安装Selenium库:pip3 install selenium

配置环境变量:

确保ChromeDriver的路径被添加到系统的PATH环境变量中,以便Selenium可以找到它。

编写Python代码:

示例代码和相关配置如下:

python 复制代码
options = webdriver.ChromeOptions()
options.add_argument('-headless')
options.add_argument("--remote-debugging-port=9222")
options.add_argument("--no-sandbox")
options.add_argument("--disable-setuid-sandbox")
options.add_argument("--disable-dev-shm-using")
options.add_argument("--disable-extensions")
options.add_argument("--disable-gpu")
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
driver = webdriver.Chrome(options=options)

这些步骤涵盖了在Linux上部署Selenium,安装Google Chrome和ChromeDriver的基本过程。具体的安装命令和配置可能根据不同的Linux发行版和系统环境略有差异。参考文章提供了更详细的步骤和示例,可以进一步查阅。

相关推荐
superman超哥5 小时前
Rust 所有权的三大基本规则:内存安全的类型系统基石
开发语言·后端·rust·内存安全·rust所有权·基本规则·系统基石
七分辣度5 小时前
Python给PDF添加水印(极速版)
python·pdf
DP+GISer5 小时前
02基于pytorch的深度学习遥感地物分类全流程实战教程(包含遥感深度学习数据集制作与大图预测)-实践篇-python基础与遥感深度学习境配置
人工智能·pytorch·python·深度学习·图像分割·遥感·地物分类
菩提祖师_5 小时前
量子计算在网络安全中的应用
开发语言·javascript·爬虫·flutter
superman超哥5 小时前
Rust 线程安全性保证(Send 与 Sync):编译期并发安全的类型系统
开发语言·后端·rust·编程语言·并发安全·send与sync·rust线程
倔强的小石头_6 小时前
Python 从入门到实战(十八):学生成绩系统高级功能实战(实时通知与数据看板)
开发语言·python
weixin_462446236 小时前
Python 使用 pypdf 按指定页码范围批量拆分 PDF(分章节)
python·pdf·pdf分割
亮子AI6 小时前
【JavaScript】forEach 是按数组顺序执行吗?
开发语言·javascript·ecmascript
菩提祖师_6 小时前
基于Docker的微服务自动化部署系统
开发语言·javascript·flutter·docker
廋到被风吹走6 小时前
【Java】【JVM】内存模型
java·开发语言·jvm