本文整理汇总了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
示例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"]