selenium安装和使用

centos 利用selenium抓包

注意:安装好selenium后要在root下安装Xvfb
yum install Xvfb

  1. 先安装chrome
curl https://intoli.com/install-google-chrome.sh | bash

安装完后运行命令,得到版本信息
google-chrome --version
  1. 下载chromedriver
http://chromedriver.storage.googleapis.com/index.html
注意!根据你安装的chrome版本下载chromedriver

比如你的版本信息是"Google Chrome 104.0.5112.101"

那么请前往文件夹"104.0.5112.79"并下载chromedriver_linux64.zip

解压缩并把chromedriver文件放到你python的安装目录
比如python安装目录是:'/www/server/python_manager/versions/3.9.7'
那么请放到/www/server/python_manager/versions/3.9.7/bin
  1. python使用chromedriver代码
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = webdriver.ChromeOptions()
options.add_argument("headless")
options.add_argument('--no-sandbox')
options.add_argument('--disable-gpu')
options.add_argument('--disable-dev-shm-usage')
browser = webdriver.Chrome(options=options)
browser.get("https://www.baidu.com")
  1. 注意新版本的selenium用法发生了一些变化
    https://pythoninoffice.com/fixing-attributeerror-webdriver-object-has-no-attribute-find_element_by_xpath/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值