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

相关推荐
凛铄linshuo10 分钟前
爬虫简单实操2——以贴吧为例爬取“某吧”前10页的网页代码
爬虫·python·学习
牛客企业服务13 分钟前
2025年AI面试推荐榜单,数字化招聘转型优选
人工智能·python·算法·面试·职场和发展·金融·求职招聘
charlie11451419124 分钟前
深入理解Qt的SetWindowsFlags函数
开发语言·c++·qt·原理分析
胡斌附体25 分钟前
linux测试端口是否可被外部访问
linux·运维·服务器·python·测试·端口测试·临时服务器
likeGhee1 小时前
python缓存装饰器实现方案
开发语言·python·缓存
whoarethenext1 小时前
使用 C++/Faiss 加速海量 MFCC 特征的相似性搜索
开发语言·c++·faiss
项目題供诗1 小时前
黑马python(二十五)
开发语言·python
读书点滴1 小时前
笨方法学python -练习14
java·前端·python
慌糖2 小时前
RabbitMQ:消息队列的轻量级王者
开发语言·javascript·ecmascript
笑衬人心。2 小时前
Ubuntu 22.04 修改默认 Python 版本为 Python3 笔记
笔记·python·ubuntu