當前位置: 首頁>>代碼示例>>Python>>正文


Python request.HTTPCookieProcessor方法代碼示例

本文整理匯總了Python中urllib.request.HTTPCookieProcessor方法的典型用法代碼示例。如果您正苦於以下問題:Python request.HTTPCookieProcessor方法的具體用法?Python request.HTTPCookieProcessor怎麽用?Python request.HTTPCookieProcessor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在urllib.request的用法示例。


在下文中一共展示了request.HTTPCookieProcessor方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import HTTPCookieProcessor [as 別名]
def __init__(
        self,
        host,
        port=8069,
        timeout=120,
        version=None,
        deserialize=True,
        opener=None,
    ):
        super(ConnectorJSONRPC, self).__init__(host, port, timeout, version)
        self.deserialize = deserialize
        # One URL opener (with cookies handling) shared between
        # JSON and HTTP requests
        if opener is None:
            cookie_jar = CookieJar()
            opener = build_opener(HTTPCookieProcessor(cookie_jar))
        self._opener = opener
        self._proxy_json, self._proxy_http = self._get_proxies() 
開發者ID:OCA,項目名稱:odoorpc,代碼行數:20,代碼來源:__init__.py

示例2: __init__

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import HTTPCookieProcessor [as 別名]
def __init__(self):
        self.articles = []
        self.query = None
        self.cjar = MozillaCookieJar()

        # If we have a cookie file, load it:
        if ScholarConf.COOKIE_JAR_FILE and \
           os.path.exists(ScholarConf.COOKIE_JAR_FILE):
            try:
                self.cjar.load(ScholarConf.COOKIE_JAR_FILE,
                               ignore_discard=True)
                ScholarUtils.log('info', 'loaded cookies file')
            except Exception as msg:
                ScholarUtils.log('warn', 'could not load cookies file: %s' % msg)
                self.cjar = MozillaCookieJar() # Just to be safe

        self.opener = build_opener(HTTPCookieProcessor(self.cjar))
        self.settings = None # Last settings object, if any 
開發者ID:macks22,項目名稱:dblp,代碼行數:20,代碼來源:scholar.py

示例3: download

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import HTTPCookieProcessor [as 別名]
def download(self, url, retry_count=3, headers=None, proxy=None, data=None):
        if url is None:
            return None
        try:
            req = request.Request(url, headers=headers, data=data)
            cookie = cookiejar.CookieJar()
            cookie_process = request.HTTPCookieProcessor(cookie)
            opener = request.build_opener()
            if proxy:
                proxies = {urlparse(url).scheme: proxy}
                opener.add_handler(request.ProxyHandler(proxies))
            content = opener.open(req).read()
        except error.URLError as e:
            print('HtmlDownLoader download error:', e.reason)
            content = None
            if retry_count > 0:
                if hasattr(e, 'code') and 500 <= e.code < 600:
                    #說明是 HTTPError 錯誤且 HTTP CODE 為 5XX 範圍說明是服務器錯誤,可以嘗試再次下載
                    return self.download(url, retry_count-1, headers, proxy, data)
        return content 
開發者ID:yanbober,項目名稱:SmallReptileTraining,代碼行數:22,代碼來源:html_downloader.py

示例4: __request__

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import HTTPCookieProcessor [as 別名]
def __request__(self):

        Cookiejar = CookieJar()
        opener = build_opener(HTTPCookieProcessor(Cookiejar))
        _header = dict(self.headers.items())
        if self.cookie:
            _header.update({'Cookie': self.cookie})
        req = Request(self.url, headers=_header, origin_req_host=self.host)

        res = None

        try:
            res = opener.open(req)
            # break
        except HTTPError as e:
            # if e.code >= 400 and e.code < 500:
            return e, None

        except (socket.timeout, URLError) as e:
            return e, None
        except Exception as e:
            traceback.print_exc()
            return e, None

        return res, Cookiejar._cookies 
開發者ID:ZSAIm,項目名稱:iqiyi-parser,代碼行數:27,代碼來源:DLInfos.py

示例5: cookie_friendly_download

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import HTTPCookieProcessor [as 別名]
def cookie_friendly_download(referer_url, file_url, store_dir='.', timeout=1000):
    from http.cookiejar import CookieJar
    from urllib import request
    cj = CookieJar()
    cp = request.HTTPCookieProcessor(cj)
    opener = request.build_opener(cp)
    with opener.open(referer_url) as fin:
        fin.headers.items()
    import os
    from os import path
    with opener.open(file_url, timeout=timeout) as fin:
        file_bin = fin.read()
        filename = fin.headers['Content-Disposition']
        filename = filename.split(';')[-1].split('=')[1]
        os.makedirs(store_dir, exist_ok=True)
        with open(path.join(store_dir, filename), mode='wb') as fout:
            fout.write(file_bin)
            return path.join(store_dir, filename) 
開發者ID:MikimotoH,項目名稱:DLink_Harvester,代碼行數:20,代碼來源:web_utils.py

示例6: __init__

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import HTTPCookieProcessor [as 別名]
def __init__(self, host, port, timeout=120, ssl=False, opener=None):
        self._root_url = "{http}{host}:{port}".format(
            http=(ssl and "https://" or "http://"), host=host, port=port
        )
        self._timeout = timeout
        self._builder = URLBuilder(self)
        self._opener = opener
        if not opener:
            cookie_jar = CookieJar()
            self._opener = build_opener(HTTPCookieProcessor(cookie_jar)) 
開發者ID:OCA,項目名稱:odoorpc,代碼行數:12,代碼來源:jsonrpclib.py

示例7: __init__

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import HTTPCookieProcessor [as 別名]
def __init__(self, base_url="", tag="", cookiejar=None, debug=False):
        self.tag = tag
        hh  = urllib2.HTTPHandler( debuglevel=1 if debug else 0)
        hsh = urllib2.HTTPSHandler(debuglevel=1 if debug else 0)
        cp  = urllib2.HTTPCookieProcessor(cookiejar)
        self._opener = urllib2.build_opener(hh, hsh, cp)
        scheme, netloc, path, q, f  = urlparse.urlsplit(base_url, "http")
        if not netloc:
            netloc, _, path = path.partition('/')
        self.base_url = urlparse.urlunsplit((scheme, netloc, path, q, f)) 
開發者ID:MestreLion,項目名稱:humblebundle,代碼行數:12,代碼來源:httpbot.py

示例8: nse_opener

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import HTTPCookieProcessor [as 別名]
def nse_opener(self):
        """
        builds opener for urllib2
        :return: opener object
        """
        cj = CookieJar()
        return build_opener(HTTPCookieProcessor(cj)) 
開發者ID:vsjha18,項目名稱:nsetools,代碼行數:9,代碼來源:nse.py

示例9: __init__

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import HTTPCookieProcessor [as 別名]
def __init__(self, host, port, timeout=120, ssl=False, opener=None):
        self._root_url = "{http}{host}:{port}".format(
            http=(ssl and "https://" or "http://"), host=host, port=port)
        self._timeout = timeout
        self._builder = URLBuilder(self)
        self._opener = opener
        if not opener:
            cookie_jar = CookieJar()
            self._opener = build_opener(HTTPCookieProcessor(cookie_jar)) 
開發者ID:osiell,項目名稱:odoorpc,代碼行數:11,代碼來源:jsonrpclib.py

示例10: __init__

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import HTTPCookieProcessor [as 別名]
def __init__(self):
        self.cookiejar = CookieJar()
        self._cookie_processor = HTTPCookieProcessor(self.cookiejar)
        self.form = None

        self.url = "http://0.0.0.0:8080/"
        self.path = "/"
        
        self.status = None
        self.data = None
        self._response = None
        self._forms = None 
開發者ID:Naayouu,項目名稱:Hatkey,代碼行數:14,代碼來源:browser.py

示例11: setOpener

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import HTTPCookieProcessor [as 別名]
def setOpener(self):
        """ 初始化opener
        """
        cj = cookiejar.CookieJar()
        pro = request.HTTPCookieProcessor(cj)
        self.opener = request.build_opener(pro)
        header = []
        for key, value in self._headers.items():
            elem = (key, value)
            header.append(elem)
        self.opener.addheaders = header 
開發者ID:Himself65,項目名稱:LuoguCrawler,代碼行數:13,代碼來源:LuoguBrowser.py

示例12: create_cookie_opener

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import HTTPCookieProcessor [as 別名]
def create_cookie_opener(self):
        '''
        設置啟用Cookie
        :return: 返回一個自定義的opener
        '''
        cookie = cookiejar.CookieJar()
        cookie_process = request.HTTPCookieProcessor(cookie)
        opener = request.build_opener(cookie_process)
        return opener 
開發者ID:yanbober,項目名稱:SmallReptileTraining,代碼行數:11,代碼來源:spider_main.py

示例13: __init__

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import HTTPCookieProcessor [as 別名]
def __init__(self):
        super(WebService, self).__init__()
        self.cache = defaultdict(defaultdict)
        self._cookie = CookieJar()
        self._opener = urllib2.build_opener(
            urllib2.HTTPCookieProcessor(self._cookie))
        self.query_interval = 1 
開發者ID:finalion,項目名稱:WordQuery,代碼行數:9,代碼來源:base.py

示例14: __init__

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import HTTPCookieProcessor [as 別名]
def __init__(self):
        super(WebService, self).__init__()
        self._cookie = CookieJar()
        self._opener = urllib2.build_opener(
            urllib2.HTTPCookieProcessor(self._cookie))
        self.query_interval = 1.0 
開發者ID:sth2018,項目名稱:FastWordQuery,代碼行數:8,代碼來源:base.py

示例15: initOpener

# 需要導入模塊: from urllib import request [as 別名]
# 或者: from urllib.request import HTTPCookieProcessor [as 別名]
def initOpener(self):
        self.cookiejar = CookieJar()
        self.opener = build_opener(HTTPCookieProcessor(self.cookiejar))
        self.opener.addheaders = list(self.headers.items()) 
開發者ID:ZSAIm,項目名稱:iqiyi-parser,代碼行數:6,代碼來源:common.py


注:本文中的urllib.request.HTTPCookieProcessor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。