pipelines.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:cl1024 作者: wuchujiecode 项目源码 文件源码
def process_item(self, item, spider):
        conn = MySQLdb.connect(host='localhost', user='root', passwd='wuchujie', charset='utf8', db='cl1024')
        cur = conn.cursor()
        sql = 'insert into cl1024_torrent(cl_name, cl_url, cl_bankuai, posted, torrent_url, torrent_downloaded, torrent_download_urls) values(%s, %s, %s, %s, %s, %s, %s)'
        keys = ['cl_title', 'cl_url', 'cl_bankuai', 'posted', 'torrent_url', 'torrent_downloaded', 'torrent_download_urls']
        # for i in item.keys():
        #     try:
        #         item[i] = str(item.get(i).encode('utf-8'))
        #     except:
        #         item[i] = str(item.get(i))
        #     finally:
        #         pass
        values = [item.get(x) for x in keys]
        try:
            cur.execute(sql, values)
        except MySQLdb.IntegrityError:
            pass
        conn.commit()
        cur.close()
        conn.close()
        return item
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号