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发行版和系统环境略有差异。参考文章提供了更详细的步骤和示例,可以进一步查阅。

相关推荐
zone773921 小时前
001:简单 RAG 入门
后端·python·面试
F_Quant21 小时前
🚀 Python打包踩坑指南:彻底解决 Nuitka --onefile 配置文件丢失与重启报错问题
python·操作系统
允许部分打工人先富起来1 天前
在node项目中执行python脚本
前端·python·node.js
IVEN_1 天前
Python OpenCV: RGB三色识别的最佳工程实践
python·opencv
haosend1 天前
AI时代,传统网络运维人员的转型指南
python·数据网络·网络自动化
曲幽1 天前
不止于JWT:用FastAPI的Depends实现细粒度权限控制
python·fastapi·web·jwt·rbac·permission·depends·abac
IVEN_2 天前
只会Python皮毛?深入理解这几点,轻松进阶全栈开发
python·全栈
Ray Liang2 天前
用六边形架构与整洁架构对比是伪命题?
java·python·c#·架构设计
AI攻城狮2 天前
如何给 AI Agent 做"断舍离":OpenClaw Session 自动清理实践
python
千寻girling2 天前
一份不可多得的 《 Python 》语言教程
人工智能·后端·python