當前位置: 首頁>>代碼示例>>Python>>正文


Python Request.meta['symptom_questions']方法代碼示例

本文整理匯總了Python中scrapy.http.request.Request.meta['symptom_questions']方法的典型用法代碼示例。如果您正苦於以下問題:Python Request.meta['symptom_questions']方法的具體用法?Python Request.meta['symptom_questions']怎麽用?Python Request.meta['symptom_questions']使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在scrapy.http.request.Request的用法示例。


在下文中一共展示了Request.meta['symptom_questions']方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _parse_symptom_question

# 需要導入模塊: from scrapy.http.request import Request [as 別名]
# 或者: from scrapy.http.request.Request import meta['symptom_questions'] [as 別名]
    def _parse_symptom_question(self, response):
        symptom_question_item = response.meta.get('symptom_questions')
        # print response.url
        if not symptom_question_item:
            symptom_question_item = SymptomQuestionItem()
            symptom_question_item['symptom_name'] = response.meta['symptom_item']['name']
            symptom_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()
        symptom_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 symptom_question_item
            yield symptom_question_item
        else:
            url = next_url[0]
            # print url
            # print symptom_question_item['qids']
            request = Request(url, dont_filter=True, callback=self._parse_symptom_question)
            request.meta['symptom_questions'] = symptom_question_item
            # print request
            yield request
開發者ID:whypro,項目名稱:medical_crawler,代碼行數:28,代碼來源:a120ask.py


注:本文中的scrapy.http.request.Request.meta['symptom_questions']方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。