看过非常多selenium文章,但能真正绕过的不多!下面为大家实现通过js文件注入达到真正绕过的方法!欢迎点赞关注一键三连!
一般来说普通的启用webdriver即使也是会标红的,以上是打开本地chrome的检测属性
from selenium import webdriver
class WebDriverChrome(object):
def __init__(self):
self.driver = self.StartWebdriver()
def StartWebdriver(self):
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("useAutomationExtension", False)
driver = webdriver.Chrome(options=options)
return driver
def RunStart(self):
self.driver.get('https://bot.sannysoft.com')
# time.sleep(10)
# self.driver.quit()
if __name__ == '__main__':
Crawl = WebDriverChrome()
Crawl.RunStart()
为什么我注入的js属性有效?
from selenium import webdriver
class WebDriverChrome(object):
def __init__(self):
self.driver = self.StartWebdriver()
def StartWebdriver(self):
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("useAutomationExtension", False)
driver = webdriver.Chrome(options=options)
with open('./stealth.min.js') as f:
js = f.read()
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
"source": js
})
return driver
def RunStart(self):
self.driver.get('https://bot.sannysoft.com')
# time.sleep(10)
# self.driver.quit()
if __name__ == '__main__':
Crawl = WebDriverChrome()
Crawl.RunStart()
npx extract-stealth-evasions
就会在你执行命令的文件夹下面生成一个stealth.min.js文件
我是通过everything工具找到改js文件,拷贝后再使用的,同时本站也提供了免费的直接的下载方式(stealth.min.js)。