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


Python Request.meta["is_decoration"]方法代码示例

本文整理汇总了Python中scrapy.Request.meta["is_decoration"]方法的典型用法代码示例。如果您正苦于以下问题:Python Request.meta["is_decoration"]方法的具体用法?Python Request.meta["is_decoration"]怎么用?Python Request.meta["is_decoration"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scrapy.Request的用法示例。


在下文中一共展示了Request.meta["is_decoration"]方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parse

# 需要导入模块: from scrapy import Request [as 别名]
# 或者: from scrapy.Request import meta["is_decoration"] [as 别名]
    def parse(self, response):
        select = Selector(response)
        item = TmallCategoryItem()
        
        item["category_id"] = self.getCatId(response.url)
        
        if "is_decoration" in response.meta:
            #子分类,带过来是否为装修类
            item["is_decoration"] = response.meta["is_decoration"]
        else:
            #一级分类,直接标示是否为装修类
            if item["category_id"] in self.catidIsDecrationSet:
                item["is_decoration"] = "yes"
            else:
                item["is_decoration"] = "no"
    
        # 获取子集分类id,调用callback自身
        catUrl = "https://list.tmall.com/search_product.htm?cat=%s" 
        #如果有子分类,地柜查找子分类
        cateAttrs = select.css(".cateAttrs")
        if len(cateAttrs) > 0:
            catIdList = self.catPattern.findall(cateAttrs.extract()[0])
            for catidstr in catIdList:
                catid = catidstr[self.catPrefixLen:]
                print catid
                requestUrl = catUrl % (catid)
                request = Request(requestUrl, callback=self.parse, priority=1234567)
                request.meta["is_decoration"] = item["is_decoration"]
                yield request
            pass

        item["related_product_num"] = ""
        try:
            item["related_product_num"] = select.css(".j_ResultsNumber").xpath("./span/text()")[0].extract().strip()
        except Exception,e:
            print e
开发者ID:junfeng-feng,项目名称:Spider,代码行数:38,代码来源:tmallSpider.py

示例2: Request

# 需要导入模块: from scrapy import Request [as 别名]
# 或者: from scrapy.Request import meta["is_decoration"] [as 别名]
                 valueList.append(value.extract().strip())
                 pass
             item["category_pro"][attrKey] = valueList
         except Exception,e:
             print e
         pass
     
     item["flag"] = "category"
     # 生成分类的item
     yield item
 
     # 请求品牌更多的连接
     brandUrl = "https://list.tmall.com/ajax/allBrandShowForGaiBan.htm?cat=%s" % (item["category_id"])
     request = Request(brandUrl, callback=self.brandJsonCallBack, priority=1234567)
     request.meta["category_id"] = item["category_id"]
     request.meta["is_decoration"] = item["is_decoration"]
     
     yield request
     pass
 
 def brandJsonCallBack(self, response):
     item = TmallCategoryItem()
     item["is_decoration"] =  response.meta["is_decoration"]
     
     category_id = response.meta["category_id"]
     respList = json.loads(response.body.decode("GBK").encode("utf-8"))
     
     image_urls = []
     brandList = []
     for dictItem in respList:
         href = dictItem["href"]
开发者ID:junfeng-feng,项目名称:Spider,代码行数:33,代码来源:tmallSpider.py


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