本文整理匯總了Python中scrapy.http.request.Request.meta['fprod']方法的典型用法代碼示例。如果您正苦於以下問題:Python Request.meta['fprod']方法的具體用法?Python Request.meta['fprod']怎麽用?Python Request.meta['fprod']使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scrapy.http.request.Request
的用法示例。
在下文中一共展示了Request.meta['fprod']方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: parse_subcatpage
# 需要導入模塊: from scrapy.http.request import Request [as 別名]
# 或者: from scrapy.http.request.Request import meta['fprod'] [as 別名]
def parse_subcatpage(self, response):
fobj = response.meta['fobj']
tabName = response.meta['tabName']
catName = response.meta['catName']
subcatName = response.meta['subcatName']
filter_selector = response.xpath('//div[contains(@class, "filters-outer")]')
os.chdir(currDir+"/"+tabName)
for filtr in filter_selector.xpath('.//div'):
filterNameSel = filtr.xpath('.//span[contains(@class, "filtersHeading")]/text()').extract()
if filterNameSel:
filterName = filterNameSel[0]
result = str("\n"+tabName+" -> "+catName+" -> "+subcatName+" -> "+filterName+" -> ")
#print result.encode('utf-8')
if fobj.closed:
fobj = open(fobj.name, "a+")
fobj.write("\n"+result.encode('utf-8'))
"""
worksheet.write(row,col, tabName)
worksheet.write(row+1,col, catName)
worksheet.write(row+1,col, subcatName)
worksheet.write(row+1,col, filterName)
"""
valueSelector = filtr.xpath('.//div[contains(@class, "visible-filter")]') ##fliters = filters(error in SD site)
#print valueSelector.extract()
for value in valueSelector.xpath('.//div[contains(@class, "fliters-list")]'):
valueNameSel = value.xpath('label/a/text()').extract()
if valueNameSel:
valueName = valueNameSel[0].strip()+" | "
#print valueName.encode('utf-8')
fobj.write(valueName.encode('utf-8'))
fprod = open(currDir+"/"+tabName+"/"+subcatName+".txt", 'w+')
prodSelector = response.xpath('//div[@id="products-main4"]')
#print "------------------------------------"
for product in prodSelector.xpath('.//div[@class="product_grid_box"]'):
prodNameSel = product.xpath('div[2]/div[2]/a/p/text()').extract()
prodPrice = product.xpath('.//div[@class="product-price"]/p/text()').extract()
prodLinkSel = product.xpath('div[2]/div[2]/a/@href').extract()
if prodNameSel:
prodName = prodNameSel[0]
resProd = str("\n"+prodName+ " -> ")
"""
prodFeaturesSel = product.xpath('.//ul[@id="highLights"]')
for feature in prodFeaturesSel.xpath('li'):
featNameSel = feature.xpath('text()').extract()
if featNameSel:
featName = featNameSel[0].strip()+" | "
print featName.encode('utf-8')
fobj.write(featName.encode('utf-8'))
"""
if prodLinkSel:
prodLink = prodLinkSel[0]
request = Request(prodLink,callback=self.parse_prodpage)
request.meta['fprod'] = fprod
request.meta['resProd'] = resProd
yield request
fprod.close()