selenium +chrome headless Manual 模式渲染网页

来源:互联网 发布:中国网络日报有无权威 编辑:程序博客网 时间:2024/06/05 08:56

可以看看这个里面的介绍,写得很好。https://duo.com/blog/driving-headless-chrome-with-python

 

from selenium import webdriver  from selenium.webdriver.chrome.options import Options`  chrome_options = Options()  chrome_options.add_argument("--headless")    ##需要加上,否则会弹出真实浏览器
chrome_options.binary_location ='/opt/google/chrome/chrome'
driver = webdriver.Chrome(executable_path="/home/yangdefeng/Downloads/chromedriver",chrome_options=chrome_options)

准备条件是selenium3.4 ,py2或py3,chrome 59或60版本,chrome driver 2.30。看文章里面写的介绍是chrome金丝雀版本,但59版本以后有headless模式了。


附上chromedriver下载地址
http://chromedriver.storage.googleapis.com/index.html
60版本的chrome 下载2.30就可以。