我在 postgreSQL 中插入抓取数据。这是我插入数据的scrapy代码
if spider.name == 'indianexpress':
self.cur.execute("insert into feed_indianexpress(headline,link,date) values(%s,%s,%s)", (item['headline'], item['link'],datetime.now().strftime("%H:%M:%S")))
self.connection.commit()
但我正在跟踪 Traceback
psycopg2.DataError: invalid input syntax for type timestamp with time zone: "16:40:30"
这是由于数据格式。 children 的帮助。
最佳答案
您为 date
列提供了错误的日期格式。 Postgresql 需要 yyyy-mm-dd
。
将此 datetime.now().strftime("%H:%M:%S")
更改为此 date.today().strftime("%Y-%m -%d")
关于python - 无法使用python scrapy框架在postgre中插入日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55591611/