标题内容
目前很多网站会监听是否采用自动化控制网页,监控到后会限制网站登录,这里我们采用加载一个js来隐藏我们登录的身份指纹,亲测有效!
下载指定js:
操作登录代码:
from selenium import webdriver from common.CacheConfig import * from drivers.BaseDriver import BaseDriver class ChromeDriver(BaseDriver): """Chrome 驱动器加载""" def create_driver(self,hasHeader=False): try: options = webdriver.ChromeOptions() #禁用gpu加速,防止出一些未知bug options.add_argument('--disable-gpu') options.add_experimental_option("excludeSwitches", ['enable-logging']) if hasHeader: options.add_experimental_option("excludeSwitches", ['enable-automation']) driver = webdriver.Chrome(executable_path=self.driverPath, chrome_options=options) #是否隐藏浏览器的指纹 需要存在stealth.min.js is_hide_info = ConfigCacheInfo.configDict["hide_browser_fingerprint"] if is_hide_info: with open('./stealth.min.js') as f: js = f.read() driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", { "source": js }) return driver except Exception as e: self.logger.error('create_driver Chrome Error : ' + str(e))
文章评论