本文整理匯總了Python中grab.cookie.CookieManager.update方法的典型用法代碼示例。如果您正苦於以下問題:Python CookieManager.update方法的具體用法?Python CookieManager.update怎麽用?Python CookieManager.update使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類grab.cookie.CookieManager
的用法示例。
在下文中一共展示了CookieManager.update方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Grab
# 需要導入模塊: from grab.cookie import CookieManager [as 別名]
# 或者: from grab.cookie.CookieManager import update [as 別名]
#.........這裏部分代碼省略.........
def dump_config(self):
"""
Make clone of current config.
"""
conf = copy_config(self.config, self.mutable_config_keys)
conf['state'] = {
'cookiejar_cookies': list(self.cookies.cookiejar),
}
return conf
def load_config(self, config):
"""
Configure grab instance with external config object.
"""
self.config = copy_config(config, self.mutable_config_keys)
if 'cookiejar_cookies' in config['state']:
self.cookies = CookieManager.from_cookie_list(
config['state']['cookiejar_cookies'])
def setup(self, **kwargs):
"""
Setting up Grab instance configuration.
"""
for key in kwargs:
if key not in self.config.keys():
raise error.GrabMisuseError('Unknown option: %s' % key)
if 'url' in kwargs:
if self.config.get('url'):
kwargs['url'] = self.make_url_absolute(kwargs['url'])
self.config.update(kwargs)
def go(self, url, **kwargs): # pylint: disable=invalid-name
"""
Go to ``url``
Args:
:url: could be absolute or relative. If relative then t will be
appended to the absolute URL of previous request.
"""
return self.request(url=url, **kwargs)
def download(self, url, location, **kwargs):
"""
Fetch document located at ``url`` and save to to ``location``.
"""
doc = self.go(url, **kwargs)
with open(location, 'wb') as out:
out.write(doc.body)
return len(doc.body)
def prepare_request(self, **kwargs):
"""
Configure all things to make real network request.
This method is called before doing real request via
transport extension.
"""
if self.transport is None:
self.setup_transport(self.transport_param)
self.reset()
示例2: Grab
# 需要導入模塊: from grab.cookie import CookieManager [as 別名]
# 或者: from grab.cookie.CookieManager import update [as 別名]
#.........這裏部分代碼省略.........
def load_config(self, config):
"""
Configure grab instance with external config object.
"""
self.config = copy_config(config, self.mutable_config_keys)
if 'cookiejar_cookies' in config['state']:
self.cookies = CookieManager.from_cookie_list(
config['state']['cookiejar_cookies'])
def setup(self, **kwargs):
"""
Setting up Grab instance configuration.
"""
if 'hammer_mode' in kwargs:
logging.error('Option hammer_mode is deprecated. Grab does not '
'support hammer mode anymore.')
del kwargs['hammer_mode']
if 'hammer_timeouts' in kwargs:
logging.error('Option hammer_timeouts is deprecated. Grab does not'
' support hammer mode anymore.')
del kwargs['hammer_timeouts']
for key in kwargs:
if key not in self.config.keys():
raise error.GrabMisuseError('Unknown option: %s' % key)
if 'url' in kwargs:
if self.config.get('url'):
kwargs['url'] = self.make_url_absolute(kwargs['url'])
self.config.update(kwargs)
def go(self, url, **kwargs):
"""
Go to ``url``
Args:
:url: could be absolute or relative. If relative then t will be
appended to the absolute URL of previous request.
"""
return self.request(url=url, **kwargs)
def download(self, url, location, **kwargs):
"""
Fetch document located at ``url`` and save to to ``location``.
"""
doc = self.go(url, **kwargs)
with open(location, 'wb') as out:
out.write(doc.body)
return len(doc.body)
def prepare_request(self, **kwargs):
"""
Configure all things to make real network request.
This method is called before doing real request via
transport extension.
"""
self.reset()
self.request_counter = next(REQUEST_COUNTER)
if kwargs: