【发布时间】:2015-12-04 00:10:56
【问题描述】:
我有一组机器人名称。当用户或机器人访问我的网站时,我会收到 user-agent 并想测试我的数组中的某个值是否存在于其中。
var bots = [
"twitterbot",
"linkedinbot",
"facebookexternalhit",
"pinterest",
"dotbot",
"rogerbot",
"googlebot",
"baiduspider",
"yahoo! slurp",
"bot",
"spider",
"simplepie",
"yahooseeker",
"embedly",
"quora link preview",
"outbrain",
"vkshare",
"monit",
"pingability",
"monitoring",
"winhttprequest",
"apache-httpclient",
"getprismatic.com",
"python-requests",
"twurly",
"yandex",
"browserproxy",
"webmeup-crawler",
"qwantify"
];
var isBot = function(agent){
return bots.some(function(bot){
return bot.test(agent);
});
}
app.use(function(req, res, next){
var test = isBot(req.get("user-agent").toLowerCase());
console.log(test);
});
这给了我错误:TypeError: undefined is not a function
这里出了什么问题? 如果您可以通过将我指向有用的外部链接或自己提出一些建议来帮助我扩展此机器人列表,则可以加分!
【问题讨论】:
-
加分,不错的...
标签: javascript arrays node.js express user-agent