-
Notifications
You must be signed in to change notification settings - Fork 0
/
Egoshare_1_GetCaptchas.py
executable file
·80 lines (59 loc) · 1.75 KB
/
Egoshare_1_GetCaptchas.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
#!coding: utf-8
import urllib2
import os
import cookielib
import time
#TRACEBACK
import traceback
import sys
def Myexcepthook(type, value, tb):
lines=traceback.format_exception(type, value, tb)
f=open('error.txt', 'a')
f.write("\n".join(lines))
f.close()
print "\n".join(lines)
sys.excepthook=Myexcepthook
#INSTALLATION DU COOKIE
cj = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
opener.addheaders = [('User-agent', 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'), ('Connection' , 'Keep-Alive')]
urllib2.install_opener(opener)
def html(s):
f=open("a.html","w")
f.write(s)
f.close()
os.startfile("a.html")
def request(URL, data=None, headers={}, param=0):
req = urllib2.Request(URL, data)
for key, content in headers.items():
req.add_header(key, content)
handle = urllib2.urlopen(req)
data=handle.read()
if not param:
return data, handle
else:
return data, handle, req
def write_file(file, s):
f=open(file, 'wb')
f.write(s)
f.close()
LIEN_IMAGES = "http://www.egoshare.com/captcha.php"
def save_image(i=0, path=""):
while True:
try:
a, b, req1 = request(LIEN_IMAGES, param=1)
except Exception, ex:
print "Echec ("+str(Exception)+" "+str(ex)+", nouvelle tentative dans 1s..."
time.sleep(1)
else:
break
if path is "":
file = "Egoshare/Rough Captchas/Image%03d.jpg"%i
print i
else:
file = path
write_file(file, a)
return file
if __name__ == "__main__":
for i in range(500):
save_image(i)