linux selenium使用chromedriver无界面爬虫,环境搭建

以centos为例,

google-chrome 下载:curl https://intoli.com/install-google-chrome.sh | bash

根据google-chrome版本下载 webdriver  地址https://npm.taobao.org/mirrors/chromedriver/

直接贴代码

import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options


options = Options()
options.binary_location = '/usr/bin/google-chrome'
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
chromedriver = '/usr/local/bin/chromedriver'
os.environ["webdriver.chrome.driver"] = chromedriver
browser = webdriver.Chrome(chrome_options=options,executable_path=chromedriver)

browser.get('http://www.baidu.com/')
print(browser.title)
browser.quit()

 

你可能感兴趣的:(linux selenium使用chromedriver无界面爬虫,环境搭建)