小编Ine*_*elp的帖子

为什么我的Scrapy代码返回一个空数组?

我正在为wunderground.com构建网络刮板,但是我的代码返回了inchs_rain和湿度的“ []”值。谁能知道为什么会这样吗?

# -*- coding: utf-8 -*-
import scrapy
from scrapy.selector import Selector
import time

from wunderground_scraper.items import WundergroundScraperItem


class WundergroundComSpider(scrapy.Spider):
    name = "wunderground"
    allowed_domains = ["www.wunderground.com"]
    start_urls = (
        'http://www.wunderground.com/q/zmw:10001.5.99999',
    )

    def parse(self, response):
        info_set = Selector(response).xpath('//div[@id="current"]')
        list = []
        for i in info_set:
            item = WundergroundScraperItem()
            item['description'] = i.xpath('div/div/div/div/span/text()').extract()
            item['description'] = item['description'][0]
            item['humidity'] = i.xpath('div/table/tbody/tr/td/span/span/text()').extract()
            item['inches_rain'] = i.xpath('div/table/tbody/tr/td/span/span/text()').extract()
            list.append(item)
        return list
Run Code Online (Sandbox Code Playgroud)

我也知道湿度和inches_rain项目设置为相同的xpath,但这应该是正确的,因为一旦信息进入数组,我就将它们设置为数组中的某些值。

python xpath scrapy web-scraping scrapy-spider

1
推荐指数
1
解决办法
460
查看次数

标签 统计

python ×1

scrapy ×1

scrapy-spider ×1

web-scraping ×1

xpath ×1