本文整理汇总了Python中scrapy.http.request.Request.meta['tabName']方法的典型用法代码示例。如果您正苦于以下问题:Python Request.meta['tabName']方法的具体用法?Python Request.meta['tabName']怎么用?Python Request.meta['tabName']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scrapy.http.request.Request
的用法示例。
在下文中一共展示了Request.meta['tabName']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse
# 需要导入模块: from scrapy.http.request import Request [as 别名]
# 或者: from scrapy.http.request.Request import meta['tabName'] [as 别名]
def parse(self, response):
dirname = os.getcwd()
tabs= []
tab_selector = response.xpath('//div[contains(@id, "SMWrapr")]')
### loop for all tabs
for tab in tab_selector.xpath('.//div[contains(@id, "Tab")]'):
# tabItem = TabItem()
tabNameSel = tab.xpath('div/span[2]/text()').extract()
if tabNameSel:
tabName = tabNameSel[0]
os.chdir(dirname)
if not os.path.exists(currDir+"/"+tabName):
os.makedirs(currDir+"/"+tabName)
#os.chdir(tabName)
fobj = open(currDir+"/"+tabName+".txt", 'w')
cat_selector = tab.xpath('div[2]/div[contains(@class, "SMSubCat")]')
### loop for all categories
for category in cat_selector.xpath('div'): #'.//div[contains(@class, "ht180")]
# catItem = CatItem()
catNameSel = category.xpath('div/a/@title').extract()
if catNameSel:
catName = catNameSel[0]
subcat_selector = category.xpath('.//ul')
### loop for all subcategories
for subcat in subcat_selector.xpath('.//li'):
subcatNameSel = subcat.xpath('.//a/@title').extract()
if subcatNameSel:
subcatName = subcatNameSel[0]
subcatLinkSel = subcat.xpath('.//a/@href').extract()
if subcatLinkSel:
subcatLink = subcatLinkSel[0]+"?sort=plrty"
request = Request(subcatLink,callback=self.parse_subcatpage)
request.meta['fobj'] = fobj
request.meta['tabName'] = tabName
request.meta['catName'] = catName
request.meta['subcatName'] = subcatName
yield request
#(response,tabName,catName,subcatName)
#print subcatLink
#print tabName, ":", catName, ":", subcatName
# categories.append(catItem)
#return categories
#categories = [dict(categories)]
#tabs.append(tabItem)
#return tabs
os.chdir(dirname)
fobj.close()