百度上看到的,覺得有用,留着備用
python項目中從接口獲取數據並存入本地數據庫
首先用postman測試接口
根據請求方式將數據存入數據庫中
首先用postman測試接口
通過url,選擇相應的請求方式,頭部,數據格式,點擊send看能否獲取數據
根據請求方式將數據存入數據庫中
下面是post請求方式
def get() URL = '' HEADERS = {'Content-Type': 'application/json'} JSON = {} response = request.post(URL,headers=HEADERS,json=JSON) #json.loads()用於將str類型的數據轉成dict jsondata = json.load(response.txt) for i in jsondata: date1 = i[data] type1 = i[type] ... #拼接sql語句 sql="" conn=MySQLdb.connect(host="localhost",user="root",passwd="sa",db="mytable") cursor=conn.cursor() ursor.execute(sql)