centos 利用selenium抓包
注意:安装好selenium后要在root下安装Xvfb
yum install Xvfb
- 先安装chrome
curl https://intoli.com/install-google-chrome.sh | bash
安装完后运行命令,得到版本信息
google-chrome --version
- 下载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
- 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")
- 注意新版本的selenium用法发生了一些变化
https://pythoninoffice.com/fixing-attributeerror-webdriver-object-has-no-attribute-find_element_by_xpath/