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

相关推荐
天才程序YUAN2 分钟前
Windows 11 C 盘扩容完整教程:恢复分区拦路、页面文件锁盘、WinRE 重建全记录
c语言·开发语言·windows
川冰ICE2 分钟前
JavaScript进阶③|Map_Set_WeakMap_WeakSet,新型数据结构
开发语言·javascript·数据结构
我是一颗柠檬4 分钟前
C语言最全面复习:从入门到精通(2026年)
c语言·开发语言
ch.ju5 分钟前
Java Programming Chapter 4——The set method assigns a value to the property.
java·开发语言
古城小栈7 分钟前
Rustix库:Rust 系统编程 的 基石
开发语言·后端·rust
Luminous.8 分钟前
C语言--day26
c语言·开发语言
luj_17689 分钟前
硝酸体系核关联假说解析
服务器·c语言·开发语言·经验分享·算法
大蚂蚁2号10 分钟前
本地视频转文字免费工具
python·音视频
love_muming11 分钟前
数据结构入门:栈与队列详解
java·开发语言·数据结构
Je1lyfish11 分钟前
CMU15-445 (2025 Fall/2026 Spring) Project#4 - Concurrency Control
开发语言·数据库·c++·笔记·后端·算法·系统架构