fingerprintjs/botd爬虫监听
本文介绍了如何通过FingerprintJS的BotD库检测爬虫访问。首先通过npm安装库,然后创建一个工具函数加载BotD并执行检测,返回结果包含是否为爬虫及类型。在页面中调用该函数,当检测到爬虫访问时可上报至服务器。这种方案能有效识别自动化脚本访问,保障应用安全。
·
安装:
npm run fingerprintjs/botd
使用:可以建一个utils文件,
import { load } from '@fingerprintjs/botd'
// 判断是否脚本
export async function botDetect() {
const botdPromise = load()
botdPromise
.then(botd => botd.detect())
.then(result => {
// 结果示例:{ bot: true, type: 'headless' } 或 { bot: false }
console.log('检测结果:', result)
return result.bot
})
.catch(error => console.error('检测失败:', error))
}
页面使用:
import { botDetect } from '@/utils/index.js'
// 非人操作上报
async getCollet() {
const isBot = await botDetect()
if (isBot) {
// 是爬虫则上报给接口
}
}
火山引擎开发者社区是火山引擎打造的AI技术生态平台,聚焦Agent与大模型开发,提供豆包系列模型(图像/视频/视觉)、智能分析与会话工具,并配套评测集、动手实验室及行业案例库。社区通过技术沙龙、挑战赛等活动促进开发者成长,新用户可领50万Tokens权益,助力构建智能应用。
更多推荐
所有评论(0)