source: trollforge/jylam/dlftroll/http.py @ 213

Revision 213, 1.9 KB checked in by jylam, 7 years ago (diff)
  • Added linuxfr.org account creator, only works for 2plus2equal5.org mail system (seems to be banned now)
  • Property svn:keywords set to Id
Line 
1import os
2import sys
3import urllib
4import urllib2
5import cookielib
6import random
7
8
9
10# Create an http object. First getPageWithReferer() call will get PHPSESSID (and others) cookie
11# After that, each getPageWithReferer() call will send previously gotten cookie to server
12
13class HTTP(object):
14    sProxy = "void"
15    sInited = 0
16    def __init__(self, proxyfile):
17        print "-> Getting random proxy from",proxyfile,"..."
18
19        if not( os.path.isfile(proxyfile)):
20            print "--> Error, '",  proxyfile, ",' is not a file"
21            print ""
22            sys.exit(2)
23
24       
25        proxyFile = file(proxyfile, "r")
26        proxyList = proxyFile.readlines()
27
28        num = random.randint(0, len(proxyList))
29        self.sProxy = "http://"+proxyList[random.randint(0, len(proxyList))]
30        print "--> Using proxy",  self.sProxy
31
32
33    def getPageWithReferer(self, APage, AReferer, arguments):
34
35
36        params        = urllib.urlencode(arguments)
37       
38        request      = urllib2.Request(APage, params)
39        request.add_header("referer", AReferer)
40        request.add_header("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 5.0; fr; rv:1.8.0.4) Gecko/20060508 Firefox/1.5.0.4")
41       
42#        Mozilla/5.0 (Firefox 3.1.1.7) Lunix Jewbuntu Diaper Drake
43        proxy_support = urllib2.ProxyHandler({'http' : self.sProxy})
44        opener        = urllib2.build_opener(proxy_support)
45        urllib2.install_opener(opener)
46
47        cj = cookielib.LWPCookieJar()
48        if self.sInited == 1:
49            cj.load("linuxfr.cookies");
50        opener2 = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) 
51        urllib2.install_opener(opener2)
52
53
54        try: page =  urllib2.urlopen(request).read()
55        except urllib2.HTTPError, e:
56                print e
57
58
59        if self.sInited == 0:
60            cj.save("linuxfr.cookies");
61            self.sInited = 1
62
63        opener.close();
64        return page
Note: See TracBrowser for help on using the repository browser.