1、安装Chrome
配置Google的epel源
vi /etc/yum.repos.d/google.repo |
[google] name=Google-x86_64 baseurl=http://dl.google.com/linux/rpm/stable/x86_64 enabled=1 gpgcheck=0 gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub |
# 更新yum yum update # 安装Chrome yum install google-chrome-stable |
2、ChromeDriver下载
查看Chrome版本
google-chrome --version
下载:https://npm.taobao.org/mirrors/chromedriver/
找到Chrome对应的ChromeDriver版本,并下载
wget https://npm.taobao.org/mirrors/chromedriver/86.0.4240.22/chromedriver_linux64.zip |
将下载解压的ChromeDriver放到脚本同级目录调用
3、ChromeDriver授权
chmod 755 /home/pysrcript/chromedriver |
4、测试py脚本
from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument("--headless") # 无头模式 chrome_options.add_argument('--disable-gpu') # 禁用GPU加速 chrome_options.add_argument('--no-sandbox') # 禁止沙箱模式 url="https://blog.csdn.net/" brower=webdriver.Chrome(executable_path="./chromedriver", options=chrome_options) brower.get(url) source = brower.page_source #获取网页源代码 print(source) brower.quit() |
本文内容不用于商业目的,如涉及知识产权问题,请权利人联系51Testing小编(021-64471599-8017),我们将立即处理