当前位置:首页 > Web开发 > 正文

[enable-automation])# 创建浏览器对象driver = webdriver.Chrome(opti

2024-03-31 Web开发

标签:

规避网站监测

? 此刻不少大网站有对selenium采纳了监测机制。好比正常情况下我们用浏览器访谒淘宝等网站的window.navigator.webdriver的值为undefined。而使用selenium访谒则该值为true。那么如何解决这个问题呢?

? 只需要设置Chromedriver的启动参数即可解决问题。在启动Chromedriver之前,为Chrome开启尝试性成果参数excludeSwitches,,它的值为[‘enable-automation‘],完整代码如下:

import time from selenium import webdriver from selenium.webdriver import ChromeOptions # 需要导入的类 # 创建 option 东西 option = ChromeOptions() option.add_experimental_option('excludeSwitches', ['enable-automation']) # 创建浏览器东西 driver = webdriver.Chrome(options=option) driver.implicitly_wait(10) driver.get('https://www.taobao.com/') print(driver.title) # 淘宝网 - 淘!我喜欢 time.sleep(2) driver.quit()

selenium规避网站监测

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/web/31879.html