python爬虫—>谷歌的无头浏览器和反检测
- 无头浏览:是在使用selenium是的无可视化,在后台自动运行而不显示出来
- 反检测:有些网站会检测访问的selenium是否是机器,判断是的话会不给请求
from selenium import webdriver
from time import sleep
from selenium.webdriver.chrome.options import Options
from selenium.webdriver import ChromeOptions
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
option = ChromeOptions()
option.add_experimental_option('excludeSwitches',['enable-automation'])
bre = webdriver.Chrome('./chromedriver.exe',chrome_options=chrome_options,options=option)
bre.get('http://www.baidu.com')
print(bre.page_source)
sleep(2)
bre.quit()