【发布时间】:2018-02-23 04:37:51
【问题描述】:
创建表时它工作正常,但根本不插入任何数据。有谁知道可能是什么问题?
这是我的管道
import sqlite3
class HelloPipeline(object):
def open_spider(self, spider):#
self.conn = sqlite3.connect("test.sqlite")
self.cur = self.conn.cursor()
self.cur.execute("create table if not exists test(test1 text, test2 text, test3 text,test4 text, test5 text, test6 text, test7 text);")
#pass
def close_spider(self, spider):#
self.conn.commit()
self.conn.close()
#pass
def process_item(self, item, spider):#
col = ",".join(item.keys())
placeholders = ",".join(len(item) * "?")
sql = "insert into test({}) values({})"#
self.cur.execute(sql.format(col, placeholders), item.values())
return item
这是物品
import scrapy
class HelloItem(scrapy.Item):
# define the fields for your item here like:
test1 = scrapy.Field()
...
test7 = scrapy.Field()
这是主程序
class crawler(scrapy.Spider):
...
def parse (self, response):
for data_house in jsondata["data"]["data"]:
yield scrapy.Request(house_detail_domain.format(data_house["post_id"]), self.parse_house_detail)
def parse_house_detail (self, response):
...
testitem = HelloItem()
testitem["test1"] = house_detail.select(".houseInfoTitle")
...
testitem["test7"] = house_detail.select(".facility")[0].text
return testitem
告诉我是否缺少任何信息
【问题讨论】:
-
Scrapy 蜘蛛通常使用管道。不是反过来。不知道蜘蛛如何调用管道,我不知道如何回答
-
谢谢提醒,我已经更新了代码。设置部分就像 ITEM_PIPELINES = { 'hello.pipelines.HelloPipeline': 1000, }
-
能不能给我们提供scrapy日志?
-
哇你们亲,日志太长了,我无法弄清楚,但它确实显示了问题!
标签: python sql sqlite scrapy scrapy-pipeline