python调用thor接口
实现的功能:快速访问api接口,查看状态码,响应头以及响应内容
具体调用
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# coding:utf8
import requests,json
class ThorTest(object):
def __init__(self):
pass
def test_get(self):
payload='param={"pageNum":1,"pageSize":20,"city":"全国"}' #入参
url='https://thor.weidian.com/citybusiness/activity.collectPage/1.0?'
# 如某些网站(如p站)要检查referer,就给他加上
headers = { 'User-Agent': 'Mozilla/5.0 (iPad; CPU OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1', 'content-type':'application/x-www-form-urlencoded; charset=UTF-8'}
result = requests.get(url,headers=headers,params=payload)#调用接口
print("接口地址:" + url)
print("状态码:" + str(result.status_code))
print("Headers:")
for key, value in result.headers.items(): # 获取header中的值
print(key, ": " + value)
data = result.json()['result']['exhibitList'] #结果解析
for item in data:
print('renderTitle',item['renderTitle']) #打印数据
r=ThorTest()
r.test_get()