源代码如下:
class DangdangwangPipeline(object):
def process_item(self, item, spider):
conn=pymysql.connect(host="127.0.0.1",user="root",passwd="root",db="dangdang")
for i in range(0,len(item["title"])):
title=item["title"][i]
link=item["link"][i]
comment=item["comment"][i]
sql="insert into goods(title,link,comment) values('"+title+"','"+link+"','"+comment+"')"
print(sql)
#print(title+comment+link)
conn.query(sql)
conn.close()
return item
结果如下:
insert into goods(title,link,comment) values(' 瑜伽服女透气速干弹力健身服长袖显瘦跑步运动上衣','http://product.dangdang.com/1381929698.html','1条评论')
insert into goods(title,link,comment) values(' 瑜伽服健身服运动套装女四五件套秋冬季新款运动内衣速干显瘦跑步服','http://product.dangdang.com/1367906998.html','4条评论')
insert into goods(title,link,comment) values(' 瑜伽服 秋冬舞蹈健身服套装 时尚热卖爆款瑜珈服套装女','http://product.dangdang.com/1106810849.html','3条评论')
insert into goods(title,link,comment) values(' 瑜伽服 套装 女秋冬新款舞蹈服健身服 长袖练功服','http://product.dangdang.com/1107320649.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服女秋冬四五件套装 运动健身服速干跑步服晨跑短裤背心装备瑜伽裤 五件套桔色弧线高腰款 M','http://product.dangdang.com/1437043995.html','44条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装显瘦跑步健身服长裤速干运动服装女衣宽松长袖上衣运动套装女支持礼品卡支付','http://product.dangdang.com/1061168567.html','2条评论')
insert into goods(title,link,comment) values(' 瑜伽服上衣短袖女夏跑步T恤 中长款大码宽松显瘦健身房运动服速干','http://product.dangdang.com/1177277998.html','3条评论')
insert into goods(title,link,comment) values(' 瑜伽服女夏季新短款健身T恤速干网孔拼接性感修身运动短袖','http://product.dangdang.com/1384551498.html','1条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装女三件套健身服 几何印花弹力运动服紧身款','http://product.dangdang.com/1380269498.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装女 棉麻瑜伽服休闲瑜伽服女宽松瑜珈禅修居士服女支持礼品卡支付','http://product.dangdang.com/1042428167.html','1条评论')
insert into goods(title,link,comment) values(' 瑜伽服健身长裤女夏季新款弹力跑步运动长裤吸汗速干网纱拼接','http://product.dangdang.com/1380235798.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服女三件套假两件套装运动速干跑步健身服','http://product.dangdang.com/1239503095.html','5条评论')
insert into goods(title,link,comment) values(' 瑜伽服女健身房运动套装女跑步速干宽松哈伦裤健身服女','http://product.dangdang.com/1253710467.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服女T恤夏季 健身房字母网纱透气运动速干衣跑步服 X','http://product.dangdang.com/1380849098.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装女上衣网纱拼接夏季新款 健身服吸汗速干跑步运动服','http://product.dangdang.com/1380262298.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装专业运动健身服女显瘦宽松瑜伽舞蹈服','http://product.dangdang.com/1227212090.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装女夏两件套 健身房运动套装女宽松大码','http://product.dangdang.com/1381914298.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服长袖女春上衣健身服 网纱拼接弹力修身T恤七分袖','http://product.dangdang.com/1384548398.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装春夏健身房 想、舒适跑步运动女四件套健身衣新款 黑','http://product.dangdang.com/1477534667.html','4条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装女夏季新款显瘦莫代尔专业运动瑜珈衣服宽松初学者','http://product.dangdang.com/1279302985.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装女性感网纱拼接长袖上衣T恤速干衣健身房运动套装女显瘦瑜珈服','http://product.dangdang.com/1406154069.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服三件套修身显瘦健身服女运动愈加跑步服','http://product.dangdang.com/1227203490.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装女2018新款专业运动莫代尔棉瑜珈衣服七分裤夏季带胸垫','http://product.dangdang.com/1279390785.html','1条评论')
insert into goods(title,link,comment) values(' 瑜伽服女夏季长裤跑步运动弹力
查询数据库:
mysql> select * from goods;
Empty set (0.00 sec)
没有数据啊没有数据,按照执行结果显示,显然插入操作是正确的,但是为什么没有数据呢?跪求大神解答
class DangdangwangPipeline(object):
def process_item(self, item, spider):
conn=pymysql.connect(host="127.0.0.1",user="root",passwd="root",db="dangdang")
for i in range(0,len(item["title"])):
title=item["title"][i]
link=item["link"][i]
comment=item["comment"][i]
sql="insert into goods(title,link,comment) values('"+title+"','"+link+"','"+comment+"')"
print(sql)
#print(title+comment+link)
conn.query(sql)
conn.close()
return item
结果如下:
insert into goods(title,link,comment) values(' 瑜伽服女透气速干弹力健身服长袖显瘦跑步运动上衣','http://product.dangdang.com/1381929698.html','1条评论')
insert into goods(title,link,comment) values(' 瑜伽服健身服运动套装女四五件套秋冬季新款运动内衣速干显瘦跑步服','http://product.dangdang.com/1367906998.html','4条评论')
insert into goods(title,link,comment) values(' 瑜伽服 秋冬舞蹈健身服套装 时尚热卖爆款瑜珈服套装女','http://product.dangdang.com/1106810849.html','3条评论')
insert into goods(title,link,comment) values(' 瑜伽服 套装 女秋冬新款舞蹈服健身服 长袖练功服','http://product.dangdang.com/1107320649.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服女秋冬四五件套装 运动健身服速干跑步服晨跑短裤背心装备瑜伽裤 五件套桔色弧线高腰款 M','http://product.dangdang.com/1437043995.html','44条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装显瘦跑步健身服长裤速干运动服装女衣宽松长袖上衣运动套装女支持礼品卡支付','http://product.dangdang.com/1061168567.html','2条评论')
insert into goods(title,link,comment) values(' 瑜伽服上衣短袖女夏跑步T恤 中长款大码宽松显瘦健身房运动服速干','http://product.dangdang.com/1177277998.html','3条评论')
insert into goods(title,link,comment) values(' 瑜伽服女夏季新短款健身T恤速干网孔拼接性感修身运动短袖','http://product.dangdang.com/1384551498.html','1条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装女三件套健身服 几何印花弹力运动服紧身款','http://product.dangdang.com/1380269498.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装女 棉麻瑜伽服休闲瑜伽服女宽松瑜珈禅修居士服女支持礼品卡支付','http://product.dangdang.com/1042428167.html','1条评论')
insert into goods(title,link,comment) values(' 瑜伽服健身长裤女夏季新款弹力跑步运动长裤吸汗速干网纱拼接','http://product.dangdang.com/1380235798.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服女三件套假两件套装运动速干跑步健身服','http://product.dangdang.com/1239503095.html','5条评论')
insert into goods(title,link,comment) values(' 瑜伽服女健身房运动套装女跑步速干宽松哈伦裤健身服女','http://product.dangdang.com/1253710467.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服女T恤夏季 健身房字母网纱透气运动速干衣跑步服 X','http://product.dangdang.com/1380849098.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装女上衣网纱拼接夏季新款 健身服吸汗速干跑步运动服','http://product.dangdang.com/1380262298.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装专业运动健身服女显瘦宽松瑜伽舞蹈服','http://product.dangdang.com/1227212090.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装女夏两件套 健身房运动套装女宽松大码','http://product.dangdang.com/1381914298.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服长袖女春上衣健身服 网纱拼接弹力修身T恤七分袖','http://product.dangdang.com/1384548398.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装春夏健身房 想、舒适跑步运动女四件套健身衣新款 黑','http://product.dangdang.com/1477534667.html','4条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装女夏季新款显瘦莫代尔专业运动瑜珈衣服宽松初学者','http://product.dangdang.com/1279302985.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装女性感网纱拼接长袖上衣T恤速干衣健身房运动套装女显瘦瑜珈服','http://product.dangdang.com/1406154069.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服三件套修身显瘦健身服女运动愈加跑步服','http://product.dangdang.com/1227203490.html','0条评论')
insert into goods(title,link,comment) values(' 瑜伽服套装女2018新款专业运动莫代尔棉瑜珈衣服七分裤夏季带胸垫','http://product.dangdang.com/1279390785.html','1条评论')
insert into goods(title,link,comment) values(' 瑜伽服女夏季长裤跑步运动弹力
查询数据库:
mysql> select * from goods;
Empty set (0.00 sec)
没有数据啊没有数据,按照执行结果显示,显然插入操作是正确的,但是为什么没有数据呢?跪求大神解答