-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan_license_plates.py
133 lines (110 loc) · 5.17 KB
/
scan_license_plates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from bs4 import BeautifulSoup
from requests import Request, Session
import re
import sys
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('--letters', help='letter combination. Use ? for wildcard. Max length 2 letters')
parser.add_argument('--numbers', help='number combination. Use ? for wildcard. Max length 3 digits')
args = parser.parse_args()
numbers = args.numbers
letters = args.letters
if (not numbers and not letters):
print('Mandatory parameters not set. See --help')
sys.exit(1)
if (len(numbers) > 3):
print('Only 3 Digits as numbers allowed')
sys.exit(1)
if (len(letters) > 3):
print('Only 2 letters as letters allowed')
sys.exit(1)
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'de,en-US;q=0.7,en;q=0.3',
'Accept-Encoding': 'gzip, deflate, br',
'Origin': 'https://laikra.komm.one',
'Connection': 'keep-alive',
'Referer': 'https://laikra.komm.one/dvvlaikraIGV21/servlet/Internetgeschaeftsvorfaelle?AUFRUF=WKZ_lhs',
'Upgrade-Insecure-Requests': '1',
'TE': 'Trailers'
}
s = Session()
getReq = Request(
'GET',
'https://laikra.komm.one/dvvlaikraIGV21/servlet/Internetgeschaeftsvorfaelle?AUFRUF=WKZ_lhs'
).prepare()
getResponse=s.send(getReq)
# Cookie from first Get Request we need for post request
cookies=getResponse.cookies.get_dict()
# Also save timestamp from first request. It seams with a other timestamp server is rejecting post request
soup = BeautifulSoup(getResponse.text , 'html.parser')
timestamp = soup.find('input', {'name': 'ZEITSTEMPEL'}).get('value')
data = {
"WKZ_ERKENN_Z": letters,
"WKZ_ZIFFERN": numbers,
"WKZ_SUCHMERKMAL": "NULL",
"BTN_WKZSUCHE": "suchen",
"ZEITSTEMPEL": timestamp
}
postReq = Request(
'POST',
'https://laikra.komm.one/dvvlaikraIGV21/servlet/Internetgeschaeftsvorfaelle',
files= {
'WKZ_ERKENN_Z': (None, data['WKZ_ERKENN_Z']),
'WKZ_ZIFFERN': (None, data['WKZ_ZIFFERN']),
'WKZ_SUCHMERKMAL': (None, data['WKZ_SUCHMERKMAL']),
'ZEITSTEMPEL': (None, data['ZEITSTEMPEL']),
'BTN_WKZSUCHE': (None, data['BTN_WKZSUCHE'])
},
cookies = cookies,
headers = headers
).prepare()
# Print for debug reasons
#print(postReq.headers)
#print(postReq.body.decode('utf-8'))
# send post request
postRes = s.send(postReq)
soup = BeautifulSoup(postRes.text , 'html.parser')
title = soup.find('title')
print(title)
print(r"""
/\ \__ /\ \__/\ \__ /\ \__
____\ \ ,_\ __ __\ \ ,_\ \ ,_\ __ __ _ __\ \ ,_\
/',__\\ \ \/ /\ \/\ \\ \ \/\ \ \/ /'_ `\ /'__`\ /\`'__\ \ \/
/\__, `\\ \ \_\ \ \_\ \\ \ \_\ \ \_/\ \L\ \/\ \L\.\_\ \ \/ \ \ \_
\/\____/ \ \__\\ \____/ \ \__\\ \__\ \____ \ \__/.\_\\ \_\ \ \__\
\/___/ \/__/ \/___/ \/__/ \/__/\/___L\ \/__/\/_/ \/_/ \/__/
/\____/
\_/__/
___ ___ __
/\_ \ __ /\_ \ /\ \__
\//\ \ /\_\ ___ __ ___ ____ __ _____\//\ \ __ \ \ ,_\ __
\ \ \ \/\ \ /'___\ /'__`\/' _ `\ /',__\ /'__`\ /\ '__`\\ \ \ /'__`\ \ \ \/ /'__`\
\_\ \_\ \ \/\ \__//\ __//\ \/\ \/\__, `\/\ __/ \ \ \L\ \\_\ \_/\ \L\.\_\ \ \_/\ __/
/\____\\ \_\ \____\ \____\ \_\ \_\/\____/\ \____\ \ \ ,__//\____\ \__/.\_\\ \__\ \____\
\/____/ \/_/\/____/\/____/\/_/\/_/\/___/ \/____/ \ \ \/ \/____/\/__/\/_/ \/__/\/____/
\ \_\
\/_/
____ ___ __ ___ ___ __ _ __
/',__\ /'___\ /'__`\ /' _ `\ /' _ `\ /'__`\/\`'__\
/\__, `\/\ \__//\ \L\.\_/\ \/\ \/\ \/\ \/\ __/\ \ \/
\/\____/\ \____\ \__/.\_\ \_\ \_\ \_\ \_\ \____\\ \_\
\/___/ \/____/\/__/\/_/\/_/\/_/\/_/\/_/\/____/ \/_/
""")
# check if 'blaettern' exists, which indicates, more results available than shown - todo
span = soup.select(".blaettern span")
if (len(span) > 0):
print()
print('WARNING: There are more Results than shown. Pagination is not supported yet')
print(f' ---> {span[0].get_text(strip=True)}')
print()
selected = soup.findAll('div', id=re.compile(r"^OPT_KENNZEICHENSUCHE_TREFFER\d+"))
print(f'Found {len(selected)} Results for S-{letters} {numbers}:')
print('-------------------------------------------------------------------')
# Check amount of found Results
if (len(selected) > 0):
for entry in selected:
print(entry.get_text(strip=True))
else:
print("No Results available")
print('==================================================================')