1、Chrome 版本小于88
web = Chrome()
web.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocumemt",{
"source": """
navigator.webdriver = undefined
Object.defineProperty(navigator,'webdriver',{
get:() ==> undefined
})
"""
})
web.post(url,data,headers)
2、Chrome版本大于等于88
option = Options()
option.add_argument('--disable-blink-features=AutomationControlled')
web = Chrome(options=option)
web.get(url)
3、其他的浏览器操作
option = Options()
option.add_argument('--headless')
web = Chrome(optinos=option)
option.add_argument("--auto-open-devtools-for-tabs")
option.add_experimental_option('excludeSwitches', ['enable-automation'])
mobile_emulation = {'deviceName': 'iPhone X'}
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
WIDTH = 320
HEIGHT = 640
PIXEL_RATIO = 3.0
UA = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_1 like Mac OS X) AppleWebKit/602.2.14 (KHTML, like Gecko) Version/10.0 MQQBrowser/8.8.2 Mobile/14B72c Safari/602.1 MttCustomUA/2 QBWebViewType/1 WKType/1'
mobileEmulation = {"deviceMetrics": {"width": WIDTH, "height": HEIGHT, "pixelRatio": PIXEL_RATIO}, "userAgent": UA}
options = webdriver.ChromeOptions()
options.add_experimental_option('mobileEmulation', mobileEmulation)