本文整理汇总了Python中scrapy.Request.meta['adresse']方法的典型用法代码示例。如果您正苦于以下问题:Python Request.meta['adresse']方法的具体用法?Python Request.meta['adresse']怎么用?Python Request.meta['adresse']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scrapy.Request
的用法示例。
在下文中一共展示了Request.meta['adresse']方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_depute
# 需要导入模块: from scrapy import Request [as 别名]
# 或者: from scrapy.Request import meta['adresse'] [as 别名]
def parse_depute(self, response):
depute = json.loads(response.body_as_unicode())
if 'depute' in depute:
depute = depute['depute']
depute['photo_url'] = self.photo_url % depute['slug']
req = None
for ad in depute['adresses']:
adresse = ad['adresse']
pattern = ur'Télé(phone|copie)\s*:\s*(\d[0-9 ]+\d)'
for telm in re.finditer(pattern, adresse):
if telm.group(1) == 'phone':
ad['tel'] = telm.group(2)
else:
ad['fax'] = telm.group(2)
lad = adresse.lower()
if not req and not lad.startswith(u'assemblée nationale'):
trimmed = re.sub(pattern, '', adresse)
req = Request(url=self.get_geocode_url(adresse),
callback=self.parse_geocode)
req.meta['depute'] = depute
req.meta['adresse'] = ad
if req is not None:
yield req
else:
yield depute
示例2: parse_parlementaire
# 需要导入模块: from scrapy import Request [as 别名]
# 或者: from scrapy.Request import meta['adresse'] [as 别名]
def parse_parlementaire(self, response):
rep = json.loads(response.body_as_unicode())
if 'depute' in rep:
rep = rep['depute']
rep['chambre'] = 'AN'
rep['photo_url'] = self.nd_photo_url % rep['slug']
elif 'senateur' in rep:
rep = rep['senateur']
rep['chambre'] = 'SEN'
rep['photo_url'] = self.ns_photo_url % rep['slug']
reqs = []
for ad in rep['adresses']:
adresse = ad['adresse']
pattern = ur'Télé(phone|copie)\s*:\s*(\d[0-9 ]+\d)'
for telm in re.finditer(pattern, adresse):
if telm.group(1) == 'phone':
ad['tel'] = telm.group(2)
else:
ad['fax'] = telm.group(2)
lad = adresse.lower()
if (not lad.startswith(u'assemblée nationale')
and not lad.startswith(u'sénat')):
trimmed = re.sub(pattern, '', adresse)
req = Request(url=self.get_geocode_url(trimmed),
callback=self.parse_geocode)
req.meta['rep'] = rep
req.meta['adresse'] = ad
reqs.append(req)
if len(reqs) > 0:
req = reqs.pop()
req.meta['requests'] = reqs
yield req
else:
yield rep