chrome headless 截图
http://chromedriver.storage.googleapis.com/index.html #linux版本chrome下载
https://dl.lancdn.com/landian/soft/chrome/m/ #驱动下载;驱动版本和浏览器版本需要一致
mkdir chrome
cd chrome
wget https://chromedriver.storage.googleapis.com/2.31/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
cd
vi .bashrc #添加环境变量
export PATH=/home/username/chrome:$PATH #在最后一行添加后保存退出
source ~/.bashrc #立即生效
wget https://dl.lancdn.com/landian/software/chrome/m/60.0.3112.90_amd64.deb #下载驱动
sudo apt -f -y install #-f 解决安装依赖问题
sudo dpkg -i 60.0.3112.90_amd64.deb
# 测试
# coding=utf-8
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
url="http://news.163.com/"
chrome_options = Options()
# specify headless mode
chrome_options.add_argument("--headless")
browser = webdriver.Chrome(chrome_options=chrome_options)
browser.set_page_load_timeout(300)
browser.set_script_timeout(300)
browser.get(url)
title=browser.find_elements_by_xpath('//div[@id="js_top_news"]/h2/a')
print title[0].get_attribute('innerHTML')
browser.quit()
微信:jinmuqq222