【运维记录】liunx安装chrome与chromedriver

背景

很久没搞selenium了,爬虫需要使用selenium,部署到liunx上,需要使用chrome跟chromedriver。

实践过程

备注网址:https://chromedriver.chromium.org/downloads
以117版本的chrome为例,可以找到chrome、chromedriver。

1、安装chrome

wget https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/117.0.5938.92/linux64/chrome-linux64.zip
unzip chrome-linux64.zip
./chrome --version

2、安装chromedriver

wget https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/117.0.5938.92/linux64/chromedriver-linux64.zip
unzip chromedriver-linux64.zip

3、配置环境变量
4、安装selenium

pip3 install selenium

5、demo验证

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
option = webdriver.ChromeOptions()
option.add_argument("--headless")
option.add_argument('--disable-gpu')
# option.add_argument("window-size=1024,768")
option.add_argument("--no-sandbox")
s = Service(executable_path='/opt/chromedriver/chromedriver-linux64/chromedriver')#selenium4中,把executable_path重构到了service中,如果系统变量中已有driver路径,则可以省略此行
driver = webdriver.Chrome(service=s,options=option)
driver.get("https://www.xueqiu.com/")
cookies = driver.get_cookies()
print(cookies)

以上,over!

参考链接:
centos7中配置python爬虫selenium+chromium+chromedriver环境

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值