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


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

本文整理汇总了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()        
开发者ID:ank-26,项目名称:Ecomm,代码行数:72,代码来源:snapdeal_spider.py


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