ERICYAOHAHA 2020-05-25 00:14 采纳率: 0%
浏览 170
已结题

为何pyspider运行成功后Results为空?

from pyspider.libs.base_handler import *

import re

class Handler(BaseHandler):
crawl_config = {
}

def __init__(self):
    self.urls=[
     "www.wego.cn/airports/airport-name/a",
     "www.wego.cn/airports/airport-name/b",
     "www.wego.cn/airports/airport-name/c",
     "www.wego.cn/airports/airport-name/d",
     "www.wego.cn/airports/airport-name/e",
    ]

@every(minutes=24*60)
def on_start(self):
    for url in self.urls:
        self.crawl(url, callback=self.index_page,validate_cert=False)

@config(age=10*24*60*60)
def index_page(self, response):
    url_list=re.findall('<li\sclass="extra-item\sis-hidden">\s+<a\shref="([\s+\S+]*?)">          \s+\S+',response.text)
    for item in url_list:
        url="http://www.wego.cn"+item
        self.crawl(url,callback=self.detail_page,validate_cert=False)

@config(priority=2)
def detail_page(self, response):
    print("------enter matching--------")
    AirportName=re.findall('<tr>\s+<td\swidth="200">全名</td>\s+<td>([\s+\S+]*?)</td>\s+</tr>',response.text)
    IATA=re.findall('<tr>\s+<td\swidth="200">IATA\s 代码</td>\s+<td>([\s+\S+]*?)</td>\s+</tr>',response.text)
    Latitude=re.findall('<tr>\s+<td\swidth="200">纬度</td>\s+<td>([\s+\S+]*?)</td>\s+</tr>',response.text)
    Longtitude=re.findall('<tr>\s+<td\swidth="200">经度</td>\s+<td>([\s+\S+]*?)</td>\s+</tr>',response.text)
    return {
        "url": response.url,
        "AirportName":AirportName[0] if AirportName else "无",
        "IATA":IATA[0] if IATA else "无",
        "Longtitude":Longtitude[0] if Longtitude else "无",
        "Latitude":Latitude[0] if Latitude else "无"
    }
  • 写回答

1条回答 默认 最新

  • dabocaiqq 2020-05-25 14:50
    关注
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向