source: titan/mediathek/localhoster/cloudflare.py @ 42600

Last change on this file since 42600 was 42595, checked in by obi, 15 months ago

optimize cloudflare

File size: 1.2 KB
Line 
1
2import urllib2
3from lib import helpers
4import sys
5from lib.net import Net
6import lib.common as common
7import re
8
9class 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
30sys.stdout = CloudflareResolver()
31
32
Note: See TracBrowser for help on using the repository browser.