selenium简单的反爬,就是检测webdriver属性,只需要把该属性置空即可,使用cdp方法,即可在页面加载时就执行JS语句
对webdriver置空
from selenium import webdriver
from selenium.webdriver import ChromeOptions
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_experimental_option('useAutomationExtension', False)
browser = webdriver.Chrome(options=option)
browser.execute_cdp_cmd('Page.addScriptToEvaluateOnNewDocument', {
'source': 'Object.defineProperty(navigator, "webdriver", {get: () => undefined})'
})
browser.get('http://antispider1.scrape.center/')
|