|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 ycgzs98789 于 2016-10-13 20:33 编辑
网址:http://gs.amac.org.cn/amac-infodisc/res/pof/fund/index.html
python版本2.7
想获取私募基金数据,requests请求上面地址,发现请求方式为POST,数据来源为:http://gs.amac.org.cn/amac-infodisc/api/pof/fund?rand=0.45100778440775846&page=0&size=20
以session.post(url,params = data)请求,返回415错误,求帮助
代码:
- import requests
- def demo(url):
- session = requests.Session()
- res = session.get(url, headers=headers)
- content = decode_html(res.text, res.encoding)
- data = {
- "rand":0.8082704208791256,
- "page":1,
- "size":100
- }
- res2 = session.post(url2,params = data)
- print res2.url
- [color=Red]print decode_html(res2.text, res2.encoding)[/color]
- def decode_html(text, encoding):
- if text.strip() == "":
- return text
- else :
- return text.encode(encoding).decode('utf-8')
-
- url = "http://gs.amac.org.cn/amac-infodisc/res/pof/fund/index.html"
- url2 = "http://gs.amac.org.cn/amac-infodisc/api/pof/fund"
- headers = {
- 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
- 'Accept-Encoding':'gzip, deflate, sdch',
- 'Accept-Language':'zh-CN,zh;q=0.8',
- 'Cache-Control':'max-age=0',
- 'Connection':'keep-alive',
- 'Cookie':'look=first',
- 'Host':'gs.amac.org.cn',
- #'If-None-Match':'W/"57cf8d6a-2e54"',
- 'Upgrade-Insecure-Requests':'1',
- 'Referer':'http://gs.amac.org.cn/amac-infodisc/res/pof/fund/index.html',
- 'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'
- }
- if __name__ == "__main__":
- demo(url)
复制代码
以Postman去访问http://gs.amac.org.cn/amac-infodisc/api/pof/fund?rand=0.45100778440775846&page=0&size=20,也返回415错误
POST返回
求解!
|
|