当前位置: 首页>>代码示例>>Python>>正文


Python urllib2.HTTPCookieProcessor方法代码示例

本文整理汇总了Python中urllib2.HTTPCookieProcessor方法的典型用法代码示例。如果您正苦于以下问题:Python urllib2.HTTPCookieProcessor方法的具体用法?Python urllib2.HTTPCookieProcessor怎么用?Python urllib2.HTTPCookieProcessor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib2的用法示例。


在下文中一共展示了urllib2.HTTPCookieProcessor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 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: read_openload

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPCookieProcessor [as 别名]
def read_openload(url):
    default_headers = dict()
    default_headers[
        "User-Agent"] = "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3163.100 Safari/537.36"
    default_headers["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"
    default_headers["Accept-Language"] = "es-ES,es;q=0.8,en-US;q=0.5,en;q=0.3"
    default_headers["Accept-Charset"] = "UTF-8"
    default_headers["Accept-Encoding"] = "gzip"
    cj = cookielib.MozillaCookieJar()
    request_headers = default_headers.copy()
    url = urllib.quote(url, safe="%/:=&?~#+!$,;'@()*[]")
    handlers = [urllib2.HTTPHandler(debuglevel=False)]
    handlers.append(NoRedirectHandler())
    handlers.append(urllib2.HTTPCookieProcessor(cj))
    opener = urllib2.build_opener(*handlers)
    req = urllib2.Request(url, None, request_headers)
    handle = opener.open(req, timeout=None)

    return handle.headers.dict.get('location') 
开发者ID:bugatsinho,项目名称:bugatsinho.github.io,代码行数:21,代码来源:openload.py

示例3: __init__

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPCookieProcessor [as 别名]
def __init__(self, user, pwd, softId="110614",
                 softKey="469c0d8a805a40f39d3c1ec3c9281e9c",
                 codeType="1004"):
        self.softId = softId
        self.softKey = softKey
        self.user = user
        self.pwd = pwd
        self.codeType = codeType
        self.uid = "100"
        self.initUrl = "http://common.taskok.com:9000/Service/ServerConfig.aspx"
        self.version = '1.1.1.2'
        self.cookieJar = cookielib.CookieJar()
        self.opener = urllib2.build_opener(
            urllib2.HTTPCookieProcessor(self.cookieJar))
        self.loginUrl = None
        self.uploadUrl = None
        self.codeUrl = None
        self.params = []
        self.uKey = None 
开发者ID:cundi,项目名称:PySide_For_Amazon_Order,代码行数:21,代码来源:captcha_handler.py

示例4: send_post

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPCookieProcessor [as 别名]
def send_post(url, form_data_dict):
        "pass value by POST method, return response string"
        #set headers
        user_agent = \
            'Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) ' +\
            'AppleWebKit/537.36 (KHTML, like Gecko) ' +\
            'Chrome/31.0.1650.59 Mobile Safari/537.36'
        headers = {'User-Agent': user_agent}
        #convert form dict data
        data = urllib.urlencode(form_data_dict)
        #get request object
        req = urllib2.Request(url, data, headers)

        #set cookie and create a general opener instead urlopen()
        cookie = cookielib.CookieJar()  # CookieJar object to store cookie
        handler = urllib2.HTTPCookieProcessor(cookie)  # create cookie processor
        opener = urllib2.build_opener(handler)  # a general opener
        #return response page content
        response = opener.open(req, timeout=100)
        page = response.read()

        return page 
开发者ID:PytLab,项目名称:loggers,代码行数:24,代码来源:logger_base.py

示例5: login

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPCookieProcessor [as 别名]
def login():
	cookie_filename = "cookies.txt"
	cookiejar = cookielib.MozillaCookieJar(cookie_filename)
	opener = urllib2.build_opener(urllib2.HTTPRedirectHandler(),urllib2.HTTPHandler(debuglevel=0),urllib2.HTTPSHandler(debuglevel=0),urllib2.HTTPCookieProcessor(cookiejar))
	page = loadPage(opener, "https://www.linkedin.com/")
	parse = BeautifulSoup(page, "html.parser")

	csrf = parse.find(id="loginCsrfParam-login")['value']
	
	login_data = urllib.urlencode({'session_key': username, 'session_password': password, 'loginCsrfParam': csrf})
	page = loadPage(opener,"https://www.linkedin.com/uas/login-submit", login_data)
	
	parse = BeautifulSoup(page, "html.parser")
	cookie = ""
	
	try:
		cookie = cookiejar._cookies['.www.linkedin.com']['/']['li_at'].value
	except:
		sys.exit(0)
	
	cookiejar.save()
	os.remove(cookie_filename)
	return cookie 
开发者ID:mdsecactivebreach,项目名称:LinkedInt,代码行数:25,代码来源:LinkedInt.py

示例6: urlopen

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPCookieProcessor [as 别名]
def urlopen(self, url, redirect=True, **args):
        if 'data' in args and type(args['data']) == dict:
            args['data'] = json.dumps(args['data'])
            # arg['data'] = urllib.urlencode(args['data'])
            self.headers['Content-Type'] = 'application/json'
        if not redirect:
            self.opener = urllib2.build_opener(
                self.SmartRedirectHandler(),
                urllib2.HTTPCookieProcessor(self.cookiejar))
        rs = self.opener.open(
            urllib2.Request(url, headers=self.headers, **args), timeout=30)
        if 'Location' in rs.headers:
            return rs.headers.get('Location', '')
        if rs.headers.get('content-encoding', '') == 'gzip':
            content = gzip.GzipFile(fileobj=StringIO(rs.read())).read()
        else:
            content = rs.read()
        return content 
开发者ID:tacy,项目名称:plugin.video.xunleicloud,代码行数:20,代码来源:addon.py

示例7: __init__

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPCookieProcessor [as 别名]
def __init__(self, username, password):
        self._username = username
        self._password = password
        self._logger = logging.getLogger(self.__class__.__name__)

        self._url_opener = urllib2.build_opener(
                        ThrottlingHandler(0.5),
                        urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
        self._url_opener.addheaders = [('User-Agent', 
                'https://github.com/gabrielreid/polar-flow-export')]
        self._logged_in = False 
开发者ID:gabrielreid,项目名称:polar-flow-export,代码行数:13,代码来源:polarflowexport.py

示例8: __init__

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 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

示例9: getRedirect

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPCookieProcessor [as 别名]
def getRedirect(url, values = None , header = {}, connectiontype = addon.getSetting('connectiontype')):
	old_opener = urllib2._opener
	try:
		cj = cookielib.LWPCookieJar(ustvpaths.COOKIE)
		cookie_handler = urllib2.HTTPCookieProcessor(cj)
		if int(connectiontype) == 1:
			urllib2.install_opener(prepare_dns_proxy(cookie_handler))
		elif int(connectiontype) == 2:
			urllib2.install_opener(prepare_us_proxy(cookie_handler))
		elif int(connectiontype) == 3:
			handler = TorHandler()
			if ((addon.getSetting('tor_use_local') == 'true') and addon.getSetting('tor_as_service') == 'false'):
				if not handler.start_tor():
					print 'Error launching Tor. It may already be running.\n'
			urllib2.install_opener(prepare_tor_proxy(cookie_handler))
		print 'connection :: getRedirect :: url = ' + url
		if values is None:
			req = urllib2.Request(bytes(url))
		else:
			data = urllib.urlencode(values)
			req = urllib2.Request(bytes(url), data)
		header.update({'User-Agent' : 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0'})
		if int(connectiontype) == 2:
			header.update({'X-Forwarded-For' : addon.getSetting('us_proxy')})
		elif int(connectiontype) == 1:
			header.update({'X-Forwarded-For' : addon.getSetting('dns_proxy')})
		for key, value in header.iteritems():
			req.add_header(key, value)
		response = urllib2.urlopen(req, timeout = TIMEOUT)
		finalurl = response.geturl()
		response.close()
		if ((int(connectiontype) == 3) and (addon.getSetting('tor_use_local') == 'true') and (addon.getSetting('tor_as_service') == 'false')):
			if not handler.kill_tor(): 
				print 'Error killing Tor process! It may still be running.\n' 
			else: 
				print 'Tor instance killed!\n'
	except urllib2.HTTPError, error:
		print 'HTTP Error reason: ', error
		return error.read() 
开发者ID:moneymaker365,项目名称:plugin.video.ustvvod,代码行数:41,代码来源:connection.py

示例10: __init__

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPCookieProcessor [as 别名]
def __init__(self,url):
        cookie_jar = cookielib.LWPCookieJar()
        cookie = urllib2.HTTPCookieProcessor(cookie_jar)
        self.opener = urllib2.build_opener(cookie)
        user_agent="Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36"
        self.url=url
        self.send_headers={'User-Agent':user_agent} 
开发者ID:shancang,项目名称:spider,代码行数:9,代码来源:getobj.py

示例11: test_cookies

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPCookieProcessor [as 别名]
def test_cookies(self):
        cj = MockCookieJar()
        h = urllib2.HTTPCookieProcessor(cj)
        o = h.parent = MockOpener()

        req = Request("http://example.com/")
        r = MockResponse(200, "OK", {}, "")
        newreq = h.http_request(req)
        self.assertTrue(cj.ach_req is req is newreq)
        self.assertEqual(req.get_origin_req_host(), "example.com")
        self.assertTrue(not req.is_unverifiable())
        newr = h.http_response(req, r)
        self.assertTrue(cj.ec_req is req)
        self.assertTrue(cj.ec_r is r is newr) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_urllib2.py

示例12: test_cookie_redirect

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPCookieProcessor [as 别名]
def test_cookie_redirect(self):
        # cookies shouldn't leak into redirected requests
        from cookielib import CookieJar

        from test.test_cookielib import interact_netscape

        cj = CookieJar()
        interact_netscape(cj, "http://www.example.com/", "spam=eggs")
        hh = MockHTTPHandler(302, "Location: http://www.cracker.com/\r\n\r\n")
        hdeh = urllib2.HTTPDefaultErrorHandler()
        hrh = urllib2.HTTPRedirectHandler()
        cp = urllib2.HTTPCookieProcessor(cj)
        o = build_test_opener(hh, hdeh, hrh, cp)
        o.open("http://www.example.com/")
        self.assertTrue(not hh.req.has_header("Cookie")) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:17,代码来源:test_urllib2.py

示例13: login

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPCookieProcessor [as 别名]
def login(form_data):
    url = 'http://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.18)'
    headers = ('User-Agent', 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0')
    cookie = cookielib.MozillaCookieJar(cookie_file)
    handler = urllib2.HTTPCookieProcessor(cookie)
    opener = urllib2.build_opener(handler)
    opener.addheaders.append(headers)
    req = opener.open(url, form_data)
    redirect_result = req.read()
    login_pattern = r'location.replace\(\'(.*?)\'\)'
    login_url = re.search(login_pattern, redirect_result).group(1)
    opener.open(login_url).read()
    cookie.save(cookie_file, ignore_discard=True, ignore_expires=True) 
开发者ID:buxiebug,项目名称:hexo_weibo_image,代码行数:15,代码来源:weibo_util.py

示例14: request_image_url

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPCookieProcessor [as 别名]
def request_image_url(image_path):
    cookie = cookielib.MozillaCookieJar()
    cookie.load(cookie_file, ignore_expires=True, ignore_discard=True)
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))
    image_url = 'http://picupload.service.weibo.com/interface/pic_upload.php?mime=image%2Fjpeg&data=base64&url=0&markpos=1&logo=&nick=0&marks=1&app=miniblog'
    b = base64.b64encode(file(image_path).read())
    data = urllib.urlencode({'b64_data': b})
    result = opener.open(image_url, data).read()
    result = re.sub(r"<meta.*</script>", "", result, flags=re.S)
    image_result = json.loads(result)
    image_id = image_result.get('data').get('pics').get('pic_1').get('pid')
    return 'http://ww3.sinaimg.cn/large/%s' % image_id 
开发者ID:buxiebug,项目名称:hexo_weibo_image,代码行数:14,代码来源:weibo_util.py

示例15: EnableCookie

# 需要导入模块: import urllib2 [as 别名]
# 或者: from urllib2 import HTTPCookieProcessor [as 别名]
def EnableCookie(self, enableProxy):
        #"Enable cookie & proxy (if needed)."        
        cookiejar = cookielib.LWPCookieJar()#construct cookie
        cookie_support = urllib2.HTTPCookieProcessor(cookiejar)

        if enableProxy:
            proxy_support = urllib2.ProxyHandler({'http':'http://xxxxx.pac'})#use proxy
            opener = urllib2.build_opener(proxy_support, cookie_support, urllib2.HTTPHandler)
            print ("Proxy enabled")
        else:
            opener = urllib2.build_opener(cookie_support, urllib2.HTTPHandler)
        urllib2.install_opener(opener)#construct cookie's opener 
开发者ID:somethingx64,项目名称:SinaMicroblog_Creeper-Spider_VerificationCode,代码行数:14,代码来源:weibologin.py


注:本文中的urllib2.HTTPCookieProcessor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。