Ejemplo n.º 1
0
def __unprotect(initialRequest):
    parser = cParser()
    content = initialRequest.request()
    if 'Blazingfast.io' not in content:
        return content
    pattern = 'xhr\.open\("GET","([^,]+),'
    match = parser.parse(content, pattern)
    if not match[0]:
        return False
    urlParts = match[1][0].split('"')
    sid = '1200'
    url = '%s%s%s%s' % (URL_MAIN[:-1], urlParts[0], sid, urlParts[2])
    request = cRequestHandler(url, caching=False)
    request.addHeaderEntry('Referer', initialRequest.getRequestUri())
    content = request.request()
    if not check(content):
        return content  # even if its false its probably not the right content, we'll see
    cookie = getCookieString(content)
    if not cookie:
        return False
    initialRequest.caching = False
    name, value = cookie.split(';')[0].split('=')
    cookieData = dict(
        (k.strip(), v.strip())
        for k, v in (item.split("=") for item in cookie.split(";")))
    cookie = cookie_helper.create_cookie(name,
                                         value,
                                         domain=cookieData['domain'],
                                         expires=sys.maxint,
                                         discard=False)
    initialRequest.setCookie(cookie)
    content = initialRequest.request()
    return content
Ejemplo n.º 2
0
    def resolve(self, url, cookie_jar, user_agent):
        headers = {'User-agent': user_agent, 'Referer': url}

        try:
            cookie_jar.load(ignore_discard=True)
        except Exception as e:
            logger.info(e)

        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie_jar))

        request = urllib2.Request(url)
        for key in headers:
            request.add_header(key, headers[key])

        try:
            response = opener.open(request)
        except urllib2.HTTPError as e:
            response = e

        body = response.read()

        cookie_jar.extract_cookies(response, request)
        cookie_helper.check_cookies(cookie_jar)

        pattern = 'xhr\.open\("GET","([^,]+),'
        match = cParser.parse(body, pattern)
        if not match[0]:
            return
        urlParts = match[1][0].split('"')
        parsed_url = urlparse(url)
        sid = '1200'
        script_url = '%s://%s%s%s%s' % (parsed_url.scheme, parsed_url.netloc, urlParts[0], sid, urlParts[2])
        request = urllib2.Request(script_url)
        for key in headers:
            request.add_header(key, headers[key])
        try:
            response = opener.open(request)
        except urllib2.HTTPError as e:
            response = e

        body = response.read()
        cookie_jar.extract_cookies(response, request)
        cookie_helper.check_cookies(cookie_jar)

        if not self.checkBFCookie(body):
            return body  # even if its false its probably not the right content, we'll see
        cookie = self.getCookieString(body)
        if not cookie:
            return

        name, value = cookie.split(';')[0].split('=')
        cookieData = dict((k.strip(), v.strip()) for k, v in (item.split("=") for item in cookie.split(";")))
        cookie = cookie_helper.create_cookie(name, value, domain=cookieData['domain'], expires=sys.maxint, discard=False)
        cookie_jar.set_cookie(cookie)
        request = urllib2.Request(url)
        for key in headers:
            request.add_header(key, headers[key])

        try:
            response = opener.open(request)
        except urllib2.HTTPError as e:
            response = e
        return response