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

相关推荐
lly2024061 小时前
《堆的 shift down》
开发语言
黎雁·泠崖1 小时前
【魔法森林冒险】2/14 抽象层设计:Figure/Person类(所有角色的基石)
java·开发语言
生而为虫2 小时前
Selenium打开网页时保持登陆状态
selenium·测试工具
aiguangyuan2 小时前
使用LSTM进行情感分类:原理与实现剖析
人工智能·python·nlp
季明洵2 小时前
C语言实现单链表
c语言·开发语言·数据结构·算法·链表
小小张说故事2 小时前
BeautifulSoup:Python网页解析的优雅利器
后端·爬虫·python
墨雪不会编程2 小时前
C++之【深入理解Vector】三部曲最终章
开发语言·c++
luoluoal2 小时前
基于python的医疗领域用户问答的意图识别算法研究(源码+文档)
python
Shi_haoliu2 小时前
python安装操作流程-FastAPI + PostgreSQL简单流程
python·postgresql·fastapi
浅念-2 小时前
C语言编译与链接全流程:从源码到可执行程序的幕后之旅
c语言·开发语言·数据结构·经验分享·笔记·学习·算法