July 2017
Beginner to intermediate
420 pages
10h 56m
English
Maybe, we should be looking at the UserAgents too, to see if these are actual humans making requests, or not. Let's go ahead and print out all the different UserAgents that we're encountering. So, in the same spirit of the code that actually summed up the different URLs we were seeing, we can look at all the different UserAgents that we were seeing, and sort them by the most popular user_agent strings in this log:
UserAgents = {}with open(logPath, "r") as f: for line in (l.rstrip() for l in f): match= format_pat.match(line) if match: access = match.groupdict() agent = access['user_agent'] if UserAgents.has_key(agent): UserAgents[agent] = UserAgents[agent] + 1 else: UserAgents[agent] = 1results ...Read now
Unlock full access