爬虫常用mysql
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(f‘select 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( f‘insert 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)
相关推荐
CoderToy 2020-11-16
emmm00 2020-11-17
王艺强 2020-11-17
ribavnu 2020-11-16
bianruifeng 2020-11-16
wangshuangbao 2020-11-13
苏康申 2020-11-13
vivenwan 2020-11-13
moyekongling 2020-11-13
云中舞步 2020-11-12
要啥自行车一把梭 2020-11-12
aydh 2020-11-12
kuwoyinlehe 2020-11-12
minerk 2020-11-12
vitasfly 2020-11-12
jazywoo在路上 2020-11-11
敏敏张 2020-11-11
世樹 2020-11-11