时间:2021-07-01 10:21:17 帮助过:9人阅读
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)
爬虫常用mysql
标签:pymysql get 数据库 cut style sel 导出数据 set ref