本文整理汇总了Python中cookielib.CookieJar方法的典型用法代码示例。如果您正苦于以下问题:Python cookielib.CookieJar方法的具体用法?Python cookielib.CookieJar怎么用?Python cookielib.CookieJar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cookielib
的用法示例。
在下文中一共展示了cookielib.CookieJar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [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()
示例2: __init__
# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [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
示例3: test_secure
# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def test_secure(self):
from cookielib import CookieJar, DefaultCookiePolicy
for ns in True, False:
for whitespace in " ", "":
c = CookieJar()
if ns:
pol = DefaultCookiePolicy(rfc2965=False)
int = interact_netscape
vs = ""
else:
pol = DefaultCookiePolicy(rfc2965=True)
int = interact_2965
vs = "; Version=1"
c.set_policy(pol)
url = "http://www.acme.com/"
int(c, url, "foo1=bar%s%s" % (vs, whitespace))
int(c, url, "foo2=bar%s; secure%s" % (vs, whitespace))
self.assertFalse(
c._cookies["www.acme.com"]["/"]["foo1"].secure,
"non-secure cookie registered secure")
self.assertTrue(
c._cookies["www.acme.com"]["/"]["foo2"].secure,
"secure cookie registered non-secure")
示例4: test_path_mirror
# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def test_path_mirror(self):
from cookielib import CookieJar, DefaultCookiePolicy
pol = DefaultCookiePolicy(rfc2965=True)
c = CookieJar(pol)
url = "http://foo.bar.com/"
interact_2965(c, url, "spam=eggs; Version=1")
h = interact_2965(c, url)
self.assertNotIn("Path", h, "absent path returned with path present")
c = CookieJar(pol)
url = "http://foo.bar.com/"
interact_2965(c, url, 'spam=eggs; Version=1; Path=/')
h = interact_2965(c, url)
self.assertIn('$Path="/"', h, "path not returned")
示例5: test_url_encoding
# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def test_url_encoding(self):
# Try some URL encodings of the PATHs.
# (the behaviour here has changed from libwww-perl)
from cookielib import CookieJar, DefaultCookiePolicy
c = CookieJar(DefaultCookiePolicy(rfc2965=True))
interact_2965(c, "http://www.acme.com/foo%2f%25/%3c%3c%0Anew%E5/%E5",
"foo = bar; version = 1")
cookie = interact_2965(
c, "http://www.acme.com/foo%2f%25/<<%0anew�/���",
'bar=baz; path="/foo/"; version=1');
version_re = re.compile(r'^\$version=\"?1\"?', re.I)
self.assertIn("foo=bar", cookie)
self.assertRegexpMatches(cookie, version_re)
cookie = interact_2965(
c, "http://www.acme.com/foo/%25/<<%0anew�/���")
self.assertFalse(cookie)
# unicode URL doesn't raise exception
cookie = interact_2965(c, u"http://www.acme.com/\xfc")
示例6: __init__
# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def __init__(self,host=None,user=None,password=None,fileusr=None,filepwd=None):
self.user=user
self.host=host
self.password=password
self.fileusr=fileusr
self.filepwd=filepwd
self.cj=cookielib.CookieJar()
self.opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))
self.opener.addheaders.append(('User-Agent','Mozilla/5.0'))
self.opener.addheaders.append(('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'))
self.opener.addheaders.append(('Accept-Language','zh-cn,zh;q=0.5'))
self.opener.addheaders.append(('Accept-Encoding','gzip,deflate'))
self.opener.addheaders.append(('Accept-Charset','GB2312,utf-8;q=0.7,*;q=0.7'))
self.opener.addheaders.append(('Keep-Alive','115'))
self.opener.addheaders.append(('Connection','keep-alive'))
self.opener.addheaders.append(('X-Forwarded-For','219.78.113.243'))
示例7: send_post
# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [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
示例8: test_secure
# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def test_secure(self):
from cookielib import CookieJar, DefaultCookiePolicy
for ns in True, False:
for whitespace in " ", "":
c = CookieJar()
if ns:
pol = DefaultCookiePolicy(rfc2965=False)
int = interact_netscape
vs = ""
else:
pol = DefaultCookiePolicy(rfc2965=True)
int = interact_2965
vs = "; Version=1"
c.set_policy(pol)
url = "http://www.acme.com/"
int(c, url, "foo1=bar%s%s" % (vs, whitespace))
int(c, url, "foo2=bar%s; secure%s" % (vs, whitespace))
self.assertTrue(
not c._cookies["www.acme.com"]["/"]["foo1"].secure,
"non-secure cookie registered secure")
self.assertTrue(
c._cookies["www.acme.com"]["/"]["foo2"].secure,
"secure cookie registered non-secure")
示例9: cookiejar
# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def cookiejar(self, domain):
if not domain:
return None
dotdomain = domain if domain[0] == '.' else '.' + domain
exploded = dotdomain.split(".")
parent_domains = [".%s" % (".".join(exploded[x:])) for x in range(1, len(exploded) - 1)]
matching_domains = [d for d in parent_domains if d in self.cookiedict]
if not matching_domains:
return None
cj = cookielib.CookieJar()
for d in matching_domains:
for path in self.cookiedict[d]:
for cookie_name, cookie_attrs in self.cookiedict[d][path].items():
ck = cookielib.Cookie(version=cookie_attrs["version"],
name=cookie_name,
value=cookie_attrs["value"],
port=None,
port_specified=False,
domain=d,
domain_specified=True,
domain_initial_dot=False,
path=path,
path_specified=True,
secure=cookie_attrs["secure"],
expires=cookie_attrs["expires"],
discard=True,
comment=None,
comment_url=None,
rest={'HttpOnly': None},
rfc2109=False)
if cookie_attrs["port"]:
ck.port = cookie_attrs["port"]
ck.port_specified = True
cj.set_cookie(ck)
return cj
示例10: __init__
# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [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
示例11: get_response
# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def get_response(self, query):
response = None
try:
# we can't use helpers.retrieve_url because of redirects
# we need the cookie processor to handle redirects
opener = urllib_request.build_opener(urllib_request.HTTPCookieProcessor(CookieJar()))
response = opener.open(query).read().decode('utf-8')
except urllib_request.HTTPError as e:
# if the page returns a magnet redirect, used in download_torrent
if e.code == 302:
response = e.url
except Exception:
pass
return response
示例12: __init__
# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [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))
示例13: login
# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def login(self, username, password):
self.window.debug.appendPlainText('633: Process login!')
password = hashlib.md5(password.encode('utf-8')).hexdigest()
url = "https://logindict.youdao.com/login/acc/login"
payload = "username=" + urllib.quote(username) + "&password=" + password + \
"&savelogin=1&app=web&tp=urstoken&cf=7&fr=1&ru=http%3A%2F%2Fdict.youdao.com%2Fwordbook%2Fwordlist%3Fkeyfrom%3Dnull&product=DICT&type=1&um=true&savelogin=1"
headers = {
'Cache-Control': '"no-cache"',
'Referer': 'http://account.youdao.com/login?service=dict&back_url=http://dict.youdao.com/wordbook/wordlist%3Fkeyfrom%3Dlogin_from_dict2.index',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36',
'Content-Type': 'application/x-www-form-urlencoded'
}
url = url + '?' + payload
req = urllib2.Request(url, headers=headers)
cookie = cookielib.CookieJar()
self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))
self.req = urllib2.install_opener(self.opener)
urllib2.urlopen(req)
if any(username in c.value for c in cookie):
self.saveCookies(cookie)
self.window.debug.appendPlainText('652: Cookie saved')
return True
else:
self.window.debug.appendPlainText('655: Login failed')
self.error = 1
return False
示例14: __init__
# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def __init__(self, cookiejar=None):
import cookielib
if cookiejar is None:
cookiejar = cookielib.CookieJar()
self.cookiejar = cookiejar
示例15: cookieAgentFactory
# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def cookieAgentFactory(verify_path, connectTimeout=30):
customPolicy = BrowserLikePolicyForHTTPS(
Certificate.loadPEM(FilePath(verify_path).getContent()))
agent = Agent(reactor, customPolicy, connectTimeout=connectTimeout)
cookiejar = cookielib.CookieJar()
return CookieAgent(agent, cookiejar)