selenium设置请求头,防止被识别

1.Chrome

#添加请求头
    option = webdriver.ChromeOptions()
    option.add_argument('User-Agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.7\
            5 Safari/537.36')

    #实例化浏览器,并访问
    driver = webdriver.Chrome(chrome_options=option)
    driver.get('http://es.bnuz.edu.cn/')

 

 

2.PhantoJS

https://blog.csdn.net/xiongzaiabc/article/details/83987729

https://blog.csdn.net/bule_zst/article/details/77977435

 

 

3.防止被识别

# 设置为开发者模式,避免被识别
        options.add_experimental_option('excludeSwitches',
                                        ['enable-automation'])

 

你可能感兴趣的:(Selenium)