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


Python cookielib.LWPCookieJar方法代码示例

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


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

示例1: serveFile

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import LWPCookieJar [as 别名]
def serveFile(self, fURL, sendData, httphandler = None, cookienum = 0):
		cj = cookielib.LWPCookieJar(ustvpaths.COOKIE % str(cookienum))
		if httphandler is None:
			opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
		else:
			opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj), httphandler)
		request = urllib2.Request(url = fURL)
		sheaders = self.decodeHeaderString(self.headers.headers)
		del sheaders['Host']
		sheaders['User-Agent'] = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0'
		for key in sheaders:
			opener.addheaders = [(key, sheaders[key])]
		if os.path.isfile(ustvpaths.COOKIE % str(cookienum)):
			cj.load(ignore_discard = True)
			cj.add_cookie_header(request)
		response = opener.open(request, timeout = TIMEOUT)
		self.send_response(200)
		headers = response.info()
		for key in headers:
			try:
				self.send_header(key, headers[key])
			except Exception, e:
				print "Exception: ", e
				pass 
开发者ID:moneymaker365,项目名称:plugin.video.ustvvod,代码行数:26,代码来源:proxy.py

示例2: getUrlrh

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import LWPCookieJar [as 别名]
def getUrlrh(url, data=None, header={}, usecookies=True):
    cj = cookielib.LWPCookieJar()
    if usecookies:
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
        urllib2.install_opener(opener)
    if not header:
        header = {'User-Agent':UA}
    rh={}
    req = urllib2.Request(url, data, headers=header)
    try:
        response = urllib2.urlopen(req, timeout=15)
        for k in response.headers.keys(): rh[k]=response.headers[k]
        link = response.read()
        response.close()
    except:
        link=''
    c = ''.join(['%s=%s' % (c.name, c.value) for c in cj]) if cj else ''
    return link,rh 
开发者ID:bugatsinho,项目名称:bugatsinho.github.io,代码行数:20,代码来源:sport365.py

示例3: test_bad_magic

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import LWPCookieJar [as 别名]
def test_bad_magic(self):
        from cookielib import LWPCookieJar, MozillaCookieJar, LoadError
        # IOErrors (eg. file doesn't exist) are allowed to propagate
        filename = test_support.TESTFN
        for cookiejar_class in LWPCookieJar, MozillaCookieJar:
            c = cookiejar_class()
            try:
                c.load(filename="for this test to work, a file with this "
                                "filename should not exist")
            except IOError, exc:
                # exactly IOError, not LoadError
                self.assertEqual(exc.__class__, IOError)
            else:
                self.fail("expected IOError for invalid filename")
        # Invalid contents of cookies file (eg. bad magic string)
        # causes a LoadError. 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_cookielib.py

示例4: set_cookie

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import LWPCookieJar [as 别名]
def set_cookie(cookie_file):
    """
    @brief      Load cookie from file
    @param      cookie_file
    @param      user_agent
    @return     cookie, LWPCookieJar
    """
    cookie = cookielib.LWPCookieJar(cookie_file)
    try:
        cookie.load(ignore_discard=True)
    except:
        Log.error(traceback.format_exc())
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))
    opener.addheaders = Constant.HTTP_HEADER_USERAGENT
    urllib2.install_opener(opener)
    return cookie 
开发者ID:Urinx,项目名称:WeixinBot,代码行数:18,代码来源:utils.py

示例5: __init__

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import LWPCookieJar [as 别名]
def __init__(self):
        # url
        self.loginUrl = 'https://github.com/login'
        self.postUrl = 'https://github.com/session'
        self.profileUrl = 'https://github.com/settings/profile'

        # 设置请求头
        self.headers = {
            'Referer': 'https://github.com/',
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
            'Host': 'github.com'
        }

        # 设置session
        self.session = requests.session()
        # 生成github_cookie文件
        self.session.cookies = cookielib.LWPCookieJar(filename='github_cookie') 
开发者ID:lb2281075105,项目名称:Python-Spider,代码行数:19,代码来源:18 github_login.py

示例6: init_cookie_jar

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import LWPCookieJar [as 别名]
def init_cookie_jar(cookie_file=None, cookie_t=None, cookie_y=None, cookie_euconsent=None):
    cookie_jar = LWPCookieJar(cookie_file) if cookie_file else RequestsCookieJar()

    if cookie_file and os.path.exists(cookie_file):
        cookie_jar.load(ignore_discard=True)

    if args.cookie_t:
        cookie_jar.set_cookie(create_cookie('T', cookie_t))
    if cookie_y:
        cookie_jar.set_cookie(create_cookie('Y', cookie_y))
    if cookie_euconsent:
        cookie_jar.set_cookie(create_cookie('EuConsent', cookie_euconsent))

    if cookie_file:
        cookie_jar.save(ignore_discard=True)

    return cookie_jar 
开发者ID:IgnoredAmbience,项目名称:yahoo-group-archiver,代码行数:19,代码来源:yahoo.py

示例7: GET_S_VI_COOKIE

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import LWPCookieJar [as 别名]
def GET_S_VI_COOKIE(self, referer):
        cj = cookielib.LWPCookieJar(os.path.join(ADDON_PATH_PROFILE, 'cookies.lwp'))
        cj.load(os.path.join(ADDON_PATH_PROFILE, 'cookies.lwp'),ignore_discard=True)

        ck = cookielib.Cookie(version=0, name='s_cc', value='true', port=None, port_specified=False, domain='.comcast.net', domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False)
        cj.set_cookie(ck)
        ck = cookielib.Cookie(version=0, name='s_sq', value='%5B%5BB%5D%5D', port=None, port_specified=False, domain='.comcast.net', domain_specified=False, domain_initial_dot=False, path='/', path_specified=True, secure=False, expires=None, discard=True, comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False)
        cj.set_cookie(ck)
        
        url = "https://serviceos.comcast.net/b/ss/comcastnet/1/H.27.5/s41303345554477?AQB=1&pccr=true&vidn=2C0299A205011584-60000137E007532F&&ndh=1&t=17%2F9%2F2016%2016%3A23%3A32%201%20240&fid=1F8FC523BD7D4396-2E7FF98D1A765CCC&ce=UTF-8&ns=comcast&pageName=mobile%20app%20sign%20in&g=https%3A%2F%2Flogin.comcast.net%2Flogin%3Fr%3Dcomcast.net%26s%3Doauth%26continue%3Dhttps%253A%252F%252Flogin.comcast.net%252Foauth%252Fauthorize%253Fresponse_type%253Dcode%2526redirect_uri%253Dhttps%253A%252F%252Fsp.auth.adobe.com%252Fadobe-services%252Foauth2%2526state%253DQyqYoV%2526scope%253Dopenid%252520prof&cc=USD&ch=sign%20in&events=event11&c1=%2Flogin%2F%3Amobile%20app%20sign%20in&v1=%2Flogin%2F%3Amobile%20app%20sign%20in&c4=sign%20in&c7=adobepass-nbcsports&v7=adobepass-nbcsports&c23=small&c31=comcast&v31=mobile%20app%20sign%20in&c32=cim&v32=cim&c33=comcast%20net&v33=comcast%20net&c34=comcast%20net%3Asign%20in&c35=authentication&v35=authentication&c36=site%3Ahome&v36=site%3Ahome&v41=small&c44=anonymous%3Amobile%20app%20sign%20in&v47=anonymous&h1=comcast%3Acim%3Acomcast%20net%3Asign%20in%3Amobile%20app%20sign%20in&h2=%2Flogin&s=375x667&c=32&j=1.6&v=N&k=Y&bw=375&bh=667&-g=ile%252520https%253A%252F%252Flogin.comcast.net%252Fpdp%252Ftve%2526client_id%253Dadobepass-nbcsports%2526acr_values%253Durn%253Aoasis%253Anames%253Atc%253ASAML%253A2.0%253Aac%253Aclasses%253AInternetProtocol%2526response%253D1%26reqId%3D51e0dfcb-71e4-4a3f-96ad-8b8366155e6b%26ipAddrAuthn%3D1%26client_id%3Dadobepass-nbcsports&AQE=1"
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))    
        opener.addheaders = [ ("Accept", "*/*"),
                            ("Accept-Encoding", "gzip, deflate"),
                            ("Accept-Language", "en-us"),                                                        
                            ("Connection", "keep-alive"),
                            ("Referer", referer),
                            ("User-Agent", UA_IPHONE)]
        resp = opener.open(url)        
        resp.close()
        SAVE_COOKIE(cj) 
开发者ID:eracknaphobia,项目名称:plugin.video.nbcsnliveextra-legacy,代码行数:22,代码来源:comcast.py

示例8: getBrowers

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import LWPCookieJar [as 别名]
def getBrowers():
    br = mechanize.Browser(history=NoHistory())
    #options
    br.set_handle_equiv(True)
    #br.set_handle_gzip(True)
    br.set_handle_redirect(True)
    br.set_handle_referer(True)
    br.set_handle_robots(False)
    cj = cookielib.LWPCookieJar()  
    br.set_cookiejar(cj)##关联cookies  
    br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
    br.set_debug_http(False)
    br.set_debug_redirects(False)
    br.set_debug_responses(False)
    br.addheaders = [("User-agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36")]
    return br 
开发者ID:taxigps,项目名称:xbmc-addons-chinese,代码行数:18,代码来源:video.py

示例9: GET

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import LWPCookieJar [as 别名]
def GET(url, referer, post_params=None):
    headers['Referer'] = referer

    if post_params is not None:
        post_params = urllib.urlencode(post_params)
        headers['Content-Type'] = 'application/x-www-form-urlencoded'
    elif headers.has_key('Content-Type'):
        del headers['Content-Type']

    jar = cookielib.LWPCookieJar(cookiepath)
    if os.path.isfile(cookiepath):
        jar.load()

    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
    urllib2.install_opener(opener)
    req = urllib2.Request(url, post_params, headers)

    response = opener.open(req)
    the_page = response.read()
    response.close()

    jar.save()

    return the_page 
开发者ID:seppius-xbmc-repo,项目名称:ru,代码行数:26,代码来源:default.py

示例10: GET

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import LWPCookieJar [as 别名]
def GET(url, referer, post_params=None):
    headers['Referer'] = referer
    url = get_full_url(url)

    if post_params is not None:
        post_params = urllib.urlencode(post_params)
        headers['Content-Type'] = 'application/x-www-form-urlencoded'
    elif headers.has_key('Content-Type'):
        del headers['Content-Type']

    jar = cookielib.LWPCookieJar(cookiepath)
    if xbmcvfs.exists(cookiepath):
        jar.load()

    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
    urllib2.install_opener(opener)
    req = urllib2.Request(url, post_params, headers)

    response = opener.open(req)
    the_page = response.read()
    response.close()

    jar.save()

    return the_page 
开发者ID:seppius-xbmc-repo,项目名称:ru,代码行数:27,代码来源:default.py

示例11: GET

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import LWPCookieJar [as 别名]
def GET(self, url, referer, post_params=None):
        headers['Referer'] = referer
        url = self.get_full_url(url)

        if post_params is not None:
            post_params = urllib.urlencode(post_params)
            headers['Content-Type'] = 'application/x-www-form-urlencoded'
        elif headers.has_key('Content-Type'):
            del headers['Content-Type']

        jar = cookielib.LWPCookieJar(self.cookie_path)
        if xbmcvfs.exists(self.cookie_path):
            jar.load()

        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
        urllib2.install_opener(opener)
        req = urllib2.Request(url, post_params, headers)

        response = opener.open(req)
        the_page = response.read()
        response.close()

        jar.save()

        return the_page 
开发者ID:seppius-xbmc-repo,项目名称:ru,代码行数:27,代码来源:httpclient.py

示例12: __init__

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import LWPCookieJar [as 别名]
def __init__(self, username=None, password=None, filter=None, reverse_eps=False,
                 force_czech=False, order_recently_by=0):
        ContentProvider.__init__(self, name='sosac.ph', base_url=MOVIES_BASE_URL, username=username,
                                 password=password, filter=filter)
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.LWPCookieJar()))
        urllib2.install_opener(opener)
        self.reverse_eps = reverse_eps
        self.force_czech = force_czech
        self.streamujtv_user = None
        self.streamujtv_pass = None
        self.streamujtv_location = None
        self.order_recently_by = order_recently_by 
开发者ID:kodi-czsk,项目名称:plugin.video.sosac.ph,代码行数:14,代码来源:sosac.py

示例13: getRedirect

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

示例14: getUrl

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import LWPCookieJar [as 别名]
def getUrl(url, data=None, header={}, usecookies=True):
    if usecookies:
        cj = cookielib.LWPCookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
        urllib2.install_opener(opener)
    if not header:
        header = {'User-Agent': UA}
    req = urllib2.Request(url,data,headers=header)
    try:
        response = urllib2.urlopen(req, timeout=15)
        link = response.read()
        response.close()
    except:
        link=''
    return link 
开发者ID:bugatsinho,项目名称:bugatsinho.github.io,代码行数:17,代码来源:sport365.py

示例15: get_verifycode

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import LWPCookieJar [as 别名]
def get_verifycode():
    global cookie
    cookie = cookielib.LWPCookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie), urllib2.HTTPHandler)
    urllib2.install_opener(opener)
    img = urllib2.urlopen('http://xk.urp.seu.edu.cn/jw_css/getCheckCode', timeout=8)
    f = open('verifycode.jpg', 'wb')
    f.write(img.read())
    f.close()
    return 0 
开发者ID:LeonidasCl,项目名称:seu-jwc-catcher,代码行数:12,代码来源:main.py


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