本文整理匯總了Python中scrapy.http.request.Request.meta['subcatName']方法的典型用法代碼示例。如果您正苦於以下問題:Python Request.meta['subcatName']方法的具體用法?Python Request.meta['subcatName']怎麽用?Python Request.meta['subcatName']使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scrapy.http.request.Request
的用法示例。
在下文中一共展示了Request.meta['subcatName']方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: parse
# 需要導入模塊: from scrapy.http.request import Request [as 別名]
# 或者: from scrapy.http.request.Request import meta['subcatName'] [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()