码迷,mamicode.com
首页 > 数据库 > 详细

爬虫常用mysql

时间:2020-05-08 23:05:56      阅读:101      评论:0      收藏:0      [点我收藏+]

标签:pymysql   get   数据库   cut   style   sel   导出数据   set   ref   

1.导出数据

mysqldump -u root -p123456 tiantian > C:\Users\ASUS\Desktop\shangduogou.sql    

:然后输入密码

mysqldump -u dbuser -p dbname > dbname.sql

2.操作数据库

      import pymysql
title = item[title] course = item[course] knobble = item[knobble] study_count = item[study_count] href = item[href] db = pymysql.connect( host="127.0.0.1", port=3306, user="root", password="123456", database="wyzx", charset="utf8", cursorclass=pymysql.cursors.DictCursor ) # 拿到游标 cursor = db.cursor() res1 = cursor.execute(fselect id from app_title where title="{title}";) title_id = (cursor.fetchone()).get("id") # res2 = cursor.execute(f‘select id from detail where image_url="{image_url}";‘) # detail_id = (cursor.fetchone()).get("id") res3 = cursor.execute( finsert into app_coursedetail(course,knobble,study_count,href,title_id) values("{course}","{knobble}","{study_count}","{href}","{title_id}");) db.commit() cursor.close() db.close() print(title_id)

 

爬虫常用mysql

标签:pymysql   get   数据库   cut   style   sel   导出数据   set   ref   

原文地址:https://www.cnblogs.com/wukai66/p/12853453.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!