1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| >>> reg = re.compile(r'^(?P<host>.+?) \[(?P<timestamp>.+?)\] \"(?P<request>.+)\" (?P<code>\d+) (?P<nbytes>\d+|-)$')
>>> with open('access.log') as f:
... for line in f:
... print(f'{reg.search(line).groupdict()}')
...
{'host': 'wpbfl2-45.gate.net', 'timestamp': '29:23:54:20', 'request': 'GET /icons/ok2-0.gif HTTP/1.0', 'code': '200', 'nbytes': '231'}
{'host': 'tanuki.twics.com', 'timestamp': '29:23:54:25', 'request': 'GET /OSWRCRA/general/hotline/ HTTP/1.0', 'code': '200', 'nbytes': '991'}
{'host': 'tanuki.twics.com', 'timestamp': '29:23:54:37', 'request': 'GET /docs/OSWRCRA/general/hotline/95report HTTP/1.0', 'code': '302', 'nbytes': '-'}
{'host': 'wpbfl2-45.gate.net', 'timestamp': '29:23:54:37', 'request': 'GET /docs/browner/adminbio.html HTTP/1.0', 'code': '200', 'nbytes': '4217'}
{'host': 'tanuki.twics.com', 'timestamp': '29:23:54:40', 'request': 'GET /OSWRCRA/general/hotline/95report/ HTTP/1.0', 'code': '200', 'nbytes': '1250'}
{'host': 'wpbfl2-45.gate.net', 'timestamp': '29:23:55:01', 'request': 'GET /docs/browner/cbpress.gif HTTP/1.0', 'code': '200', 'nbytes': '51661'}
{'host': 'dd15-032.compuserve.com', 'timestamp': '29:23:55:21', 'request': 'GET /Access/chapter1/s2-4.html HTTP/1.0', 'code': '200', 'nbytes': '4602'}
{'host': 'tanuki.twics.com', 'timestamp': '29:23:55:23', 'request': 'GET /docs/OSWRCRA/general/hotline/95report/05_95mhr.txt.html HTTP/1.0', 'code': '200', 'nbytes': '56431'}
{'host': 'wpbfl2-45.gate.net', 'timestamp': '29:23:55:29', 'request': 'GET /docs/Access HTTP/1.0', 'code': '302', 'nbytes': '-'}
{'host': '140.112.68.165', 'timestamp': '29:23:55:33', 'request': 'GET /logos/us-flag.gif HTTP/1.0', 'code': '200', 'nbytes': '2788'}
{'host': 'wpbfl2-45.gate.net', 'timestamp': '29:23:56:14', 'request': 'GET /Access/images/epaseal.gif HTTP/1.0', 'code': '200', 'nbytes': '2624'}
{'host': 'tanuki.twics.com', 'timestamp': '29:23:56:24', 'request': 'GET /OSWRCRA/general/hotline/95report/ HTTP/1.0', 'code': '200', 'nbytes': '1250'}
{'host': 'freenet2.carleton.ca', 'timestamp': '29:23:56:36', 'request': 'GET /emap/html/regions/four/ HTTP/1.0', 'code': '200', 'nbytes': '15173'}
{'host': 'wpbfl2-45.gate.net', 'timestamp': '29:23:57:05', 'request': 'GET /waisicons/unknown.gif HTTP/1.0', 'code': '200', 'nbytes': '83'}
{'host': 'ix-mia5-17.ix.netcom.com', 'timestamp': '29:23:57:06', 'request': 'GET /OWOW/ HTTP/1.0', 'code': '200', 'nbytes': '1501'}
{'host': 'wpbfl2-45.gate.net', 'timestamp': '29:23:57:08', 'request': 'POST /cgi-bin/waisgate/134.67.99.11=earth1.epa.gov=210=/indexes/ACCESS=gopher%40earth1.epa.gov=0.00=:free HTTP/1.0', 'code': '200', 'nbytes': '26217'}
{'host': 'wpbfl2-45.gate.net', 'timestamp': '29:23:57:12', 'request': 'GET /waisicons/text.xbm HTTP/1.0', 'code': '200', 'nbytes': '527'}
{'host': 'ix-knx-tn1-22.ix.netcom.com', 'timestamp': '29:23:57:28', 'request': 'GET / HTTP/1.0', 'code': '200', 'nbytes': '4889'} |
Partager