【发布时间】:2013-09-02 10:23:48
【问题描述】:
我正在抓取一个网站并尝试将输出保存在 MongoDB 中。它看到代码是好的,但是当我尝试一个简单的输出(scrapy crawl IR -o items.json -t json)时,文件出来是空白的......但是蜘蛛的日志显示数据被抓取了......
这是我的蜘蛛代码
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from teste.items import IngressoRapidoItem
class IngressoRapidoSpider(BaseSpider):
name = "IR"
allowed_domains = ["ingressorapido.com.br"]
start_urls = (
'http://www.ingressorapido.com.br/eventos.aspx?genero=55',
)
def parse(self, response):
hxs = HtmlXPathSelector(response)
items = []
item = IngressoRapidoItem()
item['banda'] = hxs.select('normalize-space(//a[contains(@href,"Evento")] /text())').extract()
item['local'] = hxs.select('normalize-space(//td/span[contains(@style, "normal")]/text())').extract()
items.append(item)
return items
有人猜到为什么即使数据已被抓取,输出仍为空? 提前致谢
【问题讨论】:
-
日志是什么样的?可以上传内容吗?
-
如果你运行
scrapy runspider <spider_file_name>.py -o out.json会发生什么? -
alecxe,用你告诉我的命令输出完美!!!你能给我进一步解释一下为什么scrapy crawl/pipeline不工作吗?
-
我运行了你的代码并在 json 中得到了两个条目你得到了什么?
-
即“banda”:[“”],“local”:[“Teatro Riachuelo”]
标签: python json web-scraping scrapy