爬虫,用selenium打开chrome浏览器,提示人机验证、需要在框内打勾。手动打钩(实力有限,不知道该怎么在代码实现打钩)后,页面不跳转。
- 人机验证提示图片

- 扒出来的人机验证的代码
python<div class="main-wrapper" role="main"><div class="main-content"> <h1 class="zone-name-title h1">novel.munpia.com</h1> <h2 id="challenge-running" class="h2">请完成以下操作,验证您是真人。</h2> <div id="challenge-stage" style="display: flex;"> <div id="turnstile-wrapper" class="spacer"> <div> <iframe src="https://challenges.cloudflare.com/cdn-cgi/challenge-platform/h/b/turnstile/if/ov2/av0/rcv0/0/db90n/0x4AAAAAAADnPIDROrmt1Wwj/light/normal" allow="cross-origin-isolated; fullscreen" sandbox="allow-same-origin allow-scripts allow-popups" id="cf-chl-widget-db90n" tabindex="0" title="包含 Cloudflare 安全质询的小组件 " style="border: none; overflow: hidden; width: 300px; height: 65px;"> </iframe> <input type="hidden" name="cf-turnstile-response" id="cf-chl-widget-db90n_response"> </div> </div> </div>
- 我的代码
options = webdriver.ChromeOptions()
#options.add_argument('--headless')
# 设置参数
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
chrome = webdriver.Chrome(options=options)
chrome.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": """
# 这里的操作大概就是把控制台中的window.navigator.webdriver =undefined 赋值 因为人机操作会认为是Ture
Object.defineProperty(navigator, 'webdriver', {
get: () => undefined
})
"""
})
chrome.get(source_url)
time.sleep(10)
print(chrome.page_source)
chrome.get(source_url)