【问题标题】:I want store output of python pyspider script to csv or json我想将 python pyspider 脚本的输出存储到 csv 或 json
【发布时间】:2016-06-28 07:02:43
【问题描述】:

这是我制作的代码:

import json
from pyspider.libs.base_handler import *

f = open("demo.txt","w")
class Handler(BaseHandler):
    crawl_config = {
    }

    @every(minutes=0,seconds = 0)
    def on_start(self):
        self.crawl('Any URL', callback=self.index_page)

    @config(priority=2)
    def detail_page(self, response):
        img = ""
        for each in response.doc("img[id='landingImage']").items():
            img = each
        f.write("\n"+response.doc('title').text() + "\t" + response.doc("span[id^='priceblock']").text())
        return {
            "url": response.url,
            "title": response.doc('title').text(),
            "img_url":img.attr['src'],
            "Price":response.doc("span[id^='priceblock']").text(),
            "Availability":response.doc("div[id='availability']").text()
        }

在上面的代码中,我有来自链接的废弃数据,但我无法以 json 或 csv 格式输出

【问题讨论】:

    标签: python json csv pyspider


    【解决方案1】:

    您可以从 webui 下载数据,或通过覆盖 on_result 方法将数据附加到文件中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-29
      • 2021-05-17
      • 2012-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多