pyspider任务重新启动但是结果显示none

求指教,终端的报错看不太明白为啥返回是none,也不知道和on_result有什么关系

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Created on 2018-05-22 15:22:51
# Project: demo

from pyspider.libs.base_handler import *
import pymongo


class Handler(BaseHandler):
    crawl_config = {
    }
    client = pymongo.MongoClient('localhost')
    db = client['trip']

    @every(minutes=30)
    def on_start(self):
        self.crawl('https://cn.tripadvisor.com/Attractions-g186338-Activities-London_England.html', callback=self.index_page)

    @config(age=60*20)
    def index_page(self, response):
        for each in response.doc('.attraction_type_group .listing_info  div.listing_title a').items():
            self.crawl(each.attr.href,callback=self.group_detail)
        for each in response.doc('#ATTR_ENTRY_ > div.attraction_clarity_cell > div > div > div.listing_info > div.listing_title > a').items():
            self.crawl(each.attr.href,callback=self.detail_page)
            
    def group_detail(self,response):
        for each in response.doc('.listing_title a').items():
            self.crawl(each.attr.href, callback=self.detail_page)
        print(response.doc('.current').text())
        if response.doc('.current').text() == '1':
            for next in response.doc('.pageNumbers a').items():
                self.crawl(next.attr.href,callback=self.group_detail)
        
            
    @config(priority=2)
    def detail_page(self, response):
        url = response.url
        name = response.doc('.heading_title').text()    
        rating = response.doc('.autoResize').text()
        address = response.doc('.address :nth-child(n+2)').text()
        phone = response.doc('.blEntry.phone > span').text()
        return {
            'url':url,
            "name": name,
            "rating": rating,
            'address':address,
            'phone':phone,
        }
    
    
    def on_result(self,result):
        if result:
            self.save_to_mongo(result)
            
    def save_to_mongo(self,result):
        if self.db['shdu'].insert(result):
            print('save to mongo',result)

图片描述

阅读 2k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进