想从这个网站上获取人民币对美元的汇率, http://forex.jrj.com.cn/
跟踪调试的过程,发现是由这个链接获取的, http://quote1.fx168.com/jrj/CurrencyConvert/ajaxpro/CurrencyConvert.ConvertJrj,jrj.ashx
如下是我的代码 header, formdata 复制的原请求,
# -*- coding: utf-8 -*-
import requests
import json
def get_exchange():
headers = {
'Accept': '*/*',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en,zh-CN;q=0.9,zh;q=0.8,en-US;q=0.7,ja;q=0.6',
'Ajax-method': 'Calculate',
'Connection': 'keep-alive',
'Content-Length': '56',
'Content-Type': 'application/x-www-form-urlencoded',
'Host': 'quote1.fx168.com',
'Origin': 'http://quote1.fx168.com',
'Referer': 'http://quote1.fx168.com/Jrj/CurrencyConvert/ConvertJrj3.aspx',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
}
testUrl = 'http://quote1.fx168.com/jrj/CurrencyConvert/ajaxpro/CurrencyConvert.ConvertJrj,jrj.ashx'
submit_data = {"moneys": "1", "start": "美元", "end": "人民币"}
response = requests.post(testUrl, headers=headers, data=submit_data)
print(response.content)
if __name__ == '__main__':
get_exchange()
但是输入的结果却不对,
b'"word m"'
不知道我的代码问题在哪里, 请教一下。