昨天在这个上面找了好久的错,嘤嘤嘤~
很多时候我们在爬取数据存储的时候都需要将当前时间作为一个依据,在python里面没有时间类型可以直接拿来就用的。我们只需要在存储之前将时间类型稍作修饰就行。
datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
如:
#插入产品信息
insert_good_sql = """
INSERT INTO T_GOOD(good_name, good_type, img_src, good_description, how_to_use, volumetric, price,sale, spider_time)
VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s)
"""
values = (pymysql.escape_string(data_dict['good_name']), pymysql.escape_string(data_dict['good_type']),
data_dict['img_src'], pymysql.escape_string(data_dict['good_description']), data_dict['how_to_use'],
pymysql.escape_string(data_dict['volumetric']), pymysql.escape_string(data_dict['price']),
data_dict['sale'], datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
cursor.execute(insert_good_sql, values)