我正在为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,但这应该是正确的,因为一旦信息进入数组,我就将它们设置为数组中的某些值。