1 | |
---|
2 | import urllib2 |
---|
3 | from lib import helpers |
---|
4 | import sys |
---|
5 | from lib.net import Net |
---|
6 | import lib.common as common |
---|
7 | import re |
---|
8 | |
---|
9 | class CloudflareResolver(object): |
---|
10 | def __init__(self): |
---|
11 | self.net = Net(cookie_file='/mnt/network/cookies', http_debug=True, cloudflare=True) |
---|
12 | # self.net = Net(cookie_file='/mnt/network/cookies', cloudflare=True) |
---|
13 | url = str(sys.argv[1]) |
---|
14 | return self.get_answer_code(url) |
---|
15 | |
---|
16 | def get_answer_code(self, web_url): |
---|
17 | # headers = {'User-Agent': common.FF_USER_AGENT} |
---|
18 | # headers = {'User-Agent': common.RAND_UA} |
---|
19 | |
---|
20 | Domain = re.sub(r'https*:\/\/([^/]+)(\/*.*)', '\\1', web_url) |
---|
21 | headers = {'User-agent': common.FF_USER_AGENT, 'Referer': web_url, 'Host': Domain, |
---|
22 | 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', |
---|
23 | 'Content-Type': 'text/html; charset=utf-8'} |
---|
24 | |
---|
25 | html = self.net.http_GET(web_url, headers=headers).content |
---|
26 | #html = self.request(web_url, cookie_file=/mnt/network/cookies, cloudflare=True) |
---|
27 | ret = self.net.save_cookies('/mnt/network/cookies') |
---|
28 | print "html", html.encode('utf8') |
---|
29 | |
---|
30 | sys.stdout = CloudflareResolver() |
---|
31 | |
---|
32 | |
---|