爬虫常用mysql

Posted wukai66

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了爬虫常用mysql相关的知识,希望对你有一定的参考价值。

1.导出数据

mysqldump -u root -p123456 tiantian > C:UsersASUSDesktopshangduogou.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的主要内容,如果未能解决你的问题,请参考以下文章

爬虫常用mysql

爬虫常用mysql

C#常用代码片段备忘

常用python日期日志获取内容循环的代码片段

swift常用代码片段

# Java 常用代码片段