July 2017
Beginner to intermediate
420 pages
10h 56m
English
We'll actually just throw out any lines that don't have the expected 3 fields in the request. That seems like a legitimate thing to do, because this does in fact have completely useless data inside of it, it's not like we're missing out on anything here by doing that. So, we'll modify our script to do that. We've introduced an if (len(fields) == 3) line before it actually tries to process it. We'll run that:
URLCounts = {}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() request = access['request'] fields = request.split() if (len(fields) == 3): URL = fields[1] if URLCounts.has_key(URL): URLCounts[URL] = URLCounts[URL] ...Read now
Unlock full access