鱼C论坛

 找回密码
 立即注册
查看: 2836|回复: 1

python 415错误,中国证券投资基金业协会

[复制链接]
发表于 2016-10-13 18:21:17 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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错误,求帮助

代码:
  1. import requests

  2. def demo(url):
  3.     session = requests.Session()
  4.     res = session.get(url, headers=headers)
  5.     content = decode_html(res.text, res.encoding)
  6.     data = {
  7.         "rand":0.8082704208791256,
  8.         "page":1,
  9.         "size":100
  10.         }
  11.     res2 = session.post(url2,params  = data)

  12.     print res2.url
  13.     [color=Red]print decode_html(res2.text, res2.encoding)[/color]


  14. def decode_html(text, encoding):
  15.     if text.strip() == "":
  16.         return text
  17.     else :
  18.         return text.encode(encoding).decode('utf-8')
  19.    
  20. url = "http://gs.amac.org.cn/amac-infodisc/res/pof/fund/index.html"

  21. url2 = "http://gs.amac.org.cn/amac-infodisc/api/pof/fund"

  22. headers = {
  23.     'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
  24.     'Accept-Encoding':'gzip, deflate, sdch',
  25.     'Accept-Language':'zh-CN,zh;q=0.8',
  26.     'Cache-Control':'max-age=0',
  27.     'Connection':'keep-alive',
  28.     'Cookie':'look=first',
  29.     'Host':'gs.amac.org.cn',
  30.     #'If-None-Match':'W/"57cf8d6a-2e54"',
  31.     'Upgrade-Insecure-Requests':'1',
  32.     'Referer':'http://gs.amac.org.cn/amac-infodisc/res/pof/fund/index.html',
  33.     'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'
  34.             }

  35. if __name__ == "__main__":
  36.     demo(url)
复制代码


以Postman去访问http://gs.amac.org.cn/amac-infodisc/api/pof/fund?rand=0.45100778440775846&page=0&size=20,也返回415错误

POST返回

POST返回

求解!

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2016-10-15 21:03:12 | 显示全部楼层
自己回复

这是一个动态页面,后来用selenium解决了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-9 10:23

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表