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


Python Request.meta['adresse']方法代码示例

本文整理汇总了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
开发者ID:briatte,项目名称:FranceData,代码行数:34,代码来源:depute.py

示例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
开发者ID:njoyard,项目名称:FranceData,代码行数:42,代码来源:parl.py


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