-
Notifications
You must be signed in to change notification settings - Fork 0
/
urlCracker.py
143 lines (111 loc) · 2.7 KB
/
urlCracker.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
134
135
136
137
138
139
140
141
#!/usr/bin/env python3
#############
# LIBRARIES #
#############
import requests
from lxml import html
import matplotlib.pyplot as plt
import urllib
#############
# VARIABLES #
#############
numListS2V = {'0': 0,
'1': 1,
'2': 2,
'3': 3,
'4': 4,
'5': 5,
'6': 6,
'7': 7,
'8': 8,
'9': 9,
'a': 10,
'b': 11,
'c': 12,
'd': 13,
'e': 14,
'f': 15,
'g': 16,
'h': 17,
'i': 18,
'j': 19,
'k': 20,
'l': 21,
'm': 22,
'n': 23,
'o': 24,
'p': 25,
'q': 26,
'r': 27,
's': 28,
't': 29,
'u': 30,
'v': 31,
'w': 32,
'x': 33,
'y': 34,
'z': 35}
############
# FUNCTION #
############
def showImage(url):
"""
Displays the image of the given URL with Matplotlib
"""
with requests.Session() as c:
sourceCode = c.get(url).content
try:
tree = html.fromstring(sourceCode)
imgURL = tree.xpath('//img/@src')[1]
req = urllib.request.Request(imgURL, headers={'User-Agent': 'Mozilla/5.0'}) # Change the useragent in order to prevent blocking
f = urllib.request.urlopen(req)
img = plt.imread(f)
fig_size = plt.rcParams["figure.figsize"]
# fig_size[0] = 12
# fig_size[1] = 9
plt.rcParams["figure.figsize"] = fig_size
print("ImageURL:" + imgURL)
plt.imshow(img)
plt.xticks([]), plt.yticks([])
plt.show()
except Exception as e:
print(e)
print("Image does no longer exist. If it continous like this you might want to change your staring number")
def incrementUrl(url):
"""
Converts the last six base 36 number of the url to denary, adds one and converts it back to base 36. Returns the following url, unless the last possible on is reached, then it will return the first one.
"""
dataNumber = url[-6:]
# Convert base 36 number to base 10
den = 0
for digit in dataNumber:
value = numListS2V[digit]
den *= 36
den += value
# Make sure that we don't exceede the max 6 digit base 36 value
if den + 1 <= 2176782335:
den += 1
else:
den = 0
# Convert the eenary back to base 36
numListV2S = dict(map(reversed, numListS2V.items()))
numArray = []
while den:
den, value = divmod(den, 36)
numArray.append(numListV2S[value])
dataNumber = str(''.join(reversed(numArray)))
while len(dataNumber) < 6:
dataNumber = "0" + dataNumber
return "http://prntscr.com/" + dataNumber
########
# MAIN #
########
if __name__ == '__main__':
try:
url = "http://prntscr.com/" + input("Enter a random 6 digits long string containing just lowercase letters and all numbers. If most of the images don't exist anymore, you might have to restart the script and enter a different string\n")
while True:
# Check if image still exists
showImage(url)
url = incrementUrl(url)
except KeyboardInterrupt:
print("Exit\n")