python解析一个bot true一个bot列表(bot\u list)

2024-06-16 15:06:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我们有一个apache日志解析器。我们尝试了几个whay来解析bot-true-a bot列表(bot\u-list)。但没有成功。我们试着比较两个列表,但是机器人来了或者不是一个列表。你知道吗

我们想要实现的是,bot首先通过bot\u列表。所以只有通过的机器人不在机器人列表中。你知道吗

log = apache_log(lines)

for r in log: 
    bot = r['bot']



bot_list = [ "Googlebot/2.1", 
             "AhrefsBot/5.0", 
             "bingbot/2.0", 
             "DotBot/1.1", 
             "MJ12bot/v1.4.5", 
             "SearchmetricsBot", 
             "YandexBot/3.0", 
             ]

它在这条路上为一个机器人工作。你知道吗

bot = r['bot'].strip()
if not bot.startswith("Googlebot/2.1"):

这就是我们的过滤器,bot.startwith公司. 但是,我们如何才能做到这一点,首先通过bot\ u列表?你知道吗

希望有人能把我们引向正确的方向?你知道吗


Tags: inlogtrue解析器列表forapachebot
1条回答
网友
1楼 · 发布于 2024-06-16 15:06:25

如果我了解您的问题,您可能需要检查bot是否不在bot\u列表中。我建议从日志文件中获取bot名称:

bot_name = r["bot"].split(" ")[22]
if bot_name not in bot_list:

让22作为UserAgent在日志文件which you might have already customized中的位置。你知道吗

如果位置不清楚,可以使用以下功能:

if not len(filter(lambda x: x in r["bot"], bot_list)):

这和

return_list = []
for i in bot_list:
    if i in r["bot"]:
        return_list.append(i)
return len(return_list)

相关问题 更多 >