Python3.x:访问带参数链接并且获取返回json串
核心代码:
import json import xml.dom.minidom from urllib import request, parse from sqlalchemy import func url = "http://**********/queryTradingByProdTypeData.do" headerDict = {‘Host‘: ‘query.sse.com.cn‘, ‘User-Agent‘: ‘Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:54.0) Gecko/20100101 Firefox/54.0‘, ‘Accept‘: ‘*/*‘, ‘Accept-Language‘: ‘zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3‘, ‘Accept-Encoding‘: ‘gzip, deflate‘, ‘Referer‘: ‘http://**************/funddata/overview/day/‘, ‘Connection‘: ‘keep-alive‘} jsonName = ‘jsonpCallback24028‘ data = {‘jsonCallBack‘: jsonName, ‘searchDate‘: dataDate, ‘prodType‘: ‘jj‘} params = parse.urlencode(data).encode(‘utf-8‘) req = request.Request(url, headers=headerDict) page = str(request.urlopen(req, data=params).read(), encoding="utf-8") rdata = page[len(jsonName) + 1:len(page) - 1] jsondata = json.loads(rdata) print("json>>:%s" %jsondata)
原文地址:https://www.cnblogs.com/lizm166/p/8351106.html
时间: 2024-10-13 05:54:58