selenium +chrome headless Manual 模式渲染网页

可以看看这个里面的介绍,写得很好。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/xxxx/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就可以。



原文地址:https://www.cnblogs.com/ydf0509/p/7340790.html