上周用requests 抓取到fsk招聘网的信息忘记存到数据库里面了
链接:https://blog.csdn.net/qq_37561833/article/details/102770180
所以记录一下怎么把数据存到mysql数据库里面,并简单罗列一下pymysql模块的一些用法
介绍pymysql用法的链接:
https://blog.csdn.net/qq_37561833/article/details/102887329
因为之前抓取到的数据已经保存到本地的json文件中,所以现在只要读取文件即可!
json 模块提供4 种的方法:
# dumps : 把数据类型转换成字符串
# dump : 把数据类型转换成字符串并存储在文件中
# loads : 把字符串转换成数据类型
# load : 把文件打开从字符串转换成数据类型
with open(self.file_path, 'r', encoding='utf-8') as f:
data = json.load(f)
for data in all_data:
sql = 'insert into {}(job_name,job_type,pubuli_date,organ_name,request_education,request_major,' \
'request_job_years,request_count,request_detail) values ' \
'("{}","{}","{}","{}","{}","{}","{}","{}","{}")'.format(
self.my_db_table,
data['job_name'], data['job_type'], data['pubuli_date'], data['organ_name'], data['request_education'],
data['request_major'], data['request_job_years'