Loading... ## 这是一个学习笔记 <div class='handsome_aplayer player-content' data-preload="auto" data-autoplay="false" data-listMaxHeight="340px" data-order="list"> <div class="handsomePlayer-tip-loading"><span></span> <span></span> <span></span> <span></span><span></span></div><div class="handsome_aplayer_music" data-id="460476152" data-server="netease" data-type="song" data-auth="31f467b9dbb8d277d87cbf44486e4975"></div> </div> 这里主要讲解如何反selenium检测,并且成功访问http://scxk.nmpa.gov.cn:81/xk/ 仅给出初始代码,并没有完整的爬取,后面或许还有验证速率,鼠标轨迹等着你 ```python from selenium import webdriver from selenium.webdriver.support.ui import Select from selenium.webdriver.chrome.options import Options url = "http://scxk.nmpa.gov.cn:81/xk/" options = Options() options.add_argument("--incognito") # 配置隐私模式 # option.add_argument('--headless') # 配置无界面 options.add_experimental_option('excludeSwitches', ['enable-automation']) driver = webdriver.Chrome(executable_path=r'D:\chrome driver\chromedriver',options=options) driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", { "source": """ Object.defineProperty(navigator,'webdriver',{ get: () => undefined }) """ }) driver.get(url) ``` 主要通过3个翻检测叠加,基本上可以解决大多数的selenium检测 1,隐私页面的开启 <div class="tip inlineBlock info simple small"> options.add_argument("--incognito") # 配置隐私模式 </div> 2.自动化控制的隐藏 <div class="tip inlineBlock share simple small"> options.add_experimental_option('excludeSwitches', ['enable-automation']) </div> 3.属性特征的修改 <div class="tip inlineBlock success simple small"> driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", { "source": """ Object.defineProperty(navigator,'webdriver',{ get: () => undefined }) """ }) </div> Last modification:August 27, 2022 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 1 如果觉得我的内容对你有用,请随意赞赏
2 comments
2022.8.30知乎已失效
知乎过检测用这个好像没有问题吧