这是我制作的代码:
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 格式获得输出