本文整理汇总了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: