pyspider遇到的第一个坑:Active Tasks成功,Results无内容

 

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Created on 2020-01-04 16:30:27
# Project: HomeWork

 

from pyspider.libs.base_handler import *

 

class Handler(BaseHandler):
  crawl_config = {
  }

 

  @every(seconds=20)
    def on_start(self):
      self.crawl('https://fz.lianjia.com/ershoufang/co32/', callback=self.index_page,validate_cert=False,age=0)

 

  @config(age=10)
    def index_page(self, response):
      for each in response.etree.cssselect('.title a'):
        url=each.xpath("./a/@href")
        self.crawl(url, callback=self.detail_page,validate_cert=False,age=0)

 

  @config(priority=2)
  def detail_page(self, response):
    return {
      "url":response.url,
      "mainInfo":response.etree.cssselect('.room')[0].text,
      "area":response.etree.cssselect('.area')[0].text,
      "total":response.etree.cssselect('span.total')[0].text,
      "unitPrice":response.etree.cssselect('span.unitPriceValue')[0].xpath("string(.)"),
    }

你可能感兴趣的:(pyspider遇到的第一个坑:Active Tasks成功,Results无内容)