python获取网页amf的信息

来源:互联网 发布:java专业技能怎么写 编辑:程序博客网 时间:2024/05/18 13:44

首先解释一波什么是amf:AMF(Action Message Format)是Flash与服务端通信的一种常见的二进制编码模式,其传输效率高,可以在HTTP层面上传输。现在很多Flash WebGame都采用这样的消息格式。那么我们怎么获取其中的信息呢?我们需要用到pyamf这个库,同时为了方便构造请求头和解析数据包需要用到Charles。
首先通过charles去查看请求头,然后模仿这个头给服务器发送请求。
这里写图片描述
具体的不多说,给出少许代码(怕被查水表~_~)

msg = messaging.RemotingMessage(messageId=id1,                                  clientId=id,                                  operation='',                                  destination='',                                  timeToLive=0,                                  timestamp=0)  search_time = '2017-08-17'msg.body = []#根据body添加  msg.headers['DSEndpoint'] = 'my-amf'  msg.headers['DSId'] = id  # 按AMF协议编码数据  req = remoting.Request('null', body=(msg,))  env = remoting.Envelope(amfVersion=pyamf.AMF3)  env.bodies = [('/1', req)]  data = bytes(remoting.encode(env).read())  header = {            'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:54.0) Gecko/20100101 Firefox/54.0',            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',            'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',            'Accept-Encoding': 'gzip, deflate',            'Connection': 'keep-alive',            'Content-Type': 'application/x-amf'         }# 提交请求  url = ''  req = requests.post(url, data, headers=header)  # 解码AMF协议返回的数据  resp = remoting.decode(req.content)
原创粉丝点击