其他分享
首页 > 其他分享> > 雪球网接口测试

雪球网接口测试

作者:互联网

import requests
from bs4 import BeautifulSoup
import lxml

headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0",
"Cookie": "xq_a_token=b02adfc63102d5b06db993fb320f0a7524962682"}
url = "https://xueqiu.com/stock/search.json"
param = {"code": "中国平安", "size": 3, "page": 1}
res = requests.get(url=url, params=param, headers=headers)
res.encoding = "utf-8"
# 获取json格式
print(res.json())
# 获取文本格式
print(res.text)
# 获取cookie信息
print(res.request.headers.get("Cookie"))
# 断言
assert "中国平安" in res

 

标签:url,res,接口,headers,json,param,测试,print,球网
来源: https://www.cnblogs.com/zhang-da/p/15014683.html