本文整理匯總了Python中scrapy.http.request.Request.meta['disease_questions']方法的典型用法代碼示例。如果您正苦於以下問題:Python Request.meta['disease_questions']方法的具體用法?Python Request.meta['disease_questions']怎麽用?Python Request.meta['disease_questions']使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類scrapy.http.request.Request
的用法示例。
在下文中一共展示了Request.meta['disease_questions']方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _parse_disease_question
# 需要導入模塊: from scrapy.http.request import Request [as 別名]
# 或者: from scrapy.http.request.Request import meta['disease_questions'] [as 別名]
def _parse_disease_question(self, response):
disease_question_item = response.meta.get('disease_questions')
if not disease_question_item:
disease_question_item = DiseaseQuestionItem()
disease_question_item['disease_name'] = response.meta['disease_item']['name']
disease_question_item['qids'] = []
# parse
urls = response.xpath('//div[@class="p_list_li"]/div[@class="p_list_cent"]/div[@class="p_list_centt"]/dl/dt/a/@href').extract()
disease_question_item['qids'] += [u.split('/')[-1].split('.')[0] for u in urls]
# last_url = response.xpath('//div[@class="portldet-content"]/a/@href').extract()[-1]
next_url = response.xpath('//div[@class="portlet-content"]/a[text()="下一頁 >"]/@href').extract()
if not next_url:
# 所有頁都處理完了
print disease_question_item
yield disease_question_item
else:
url = next_url[0]
# print url
# print disease_question_item['qids']
request = Request(url, dont_filter=True, callback=self._parse_disease_question)
request.meta['disease_questions'] = disease_question_item
# print request
yield request