7 print("json类型转化成python数据类型",json_r)
8 except BaseException as e:
9 print("请求失败!",str(e))
10 def post(self,url,para,headers):
11 try:
12 r = requests.post(url,data=para,headers=headers)
13 print("获取返回的状态码",r.status_code)
14 json_r = r.json()
15 print("json类型转化成python数据类型",json_r)
16 except BaseException as e:
17 print("请求失败!",str(e))
18 def post_json(self,url,para,headers):
19 try:
20 data = para
21 data = json.dumps(data) #python数据类型转化为json数据类型
22 r = requests.post(url,data=data,headers=headers)
23 print("获取返回的状态码",r.status_code)
24 json_r = r.json()
25 print("json类型转化成python数据类型",json_r)
26 except BaseException as e:
27 print("请求失败!",str(e))
28
29 url = "http://v.juhe.cn/laohuangli/d"
30 para = {"key":"eeeeeeeeeeeeeeeeeeeeeeeeeeeeeee","date":"2017-3-22"}
31 headers ={}
32
33 q = Webrequests()
34
35 q.get(url,para,headers)
36 q.post(url,para,headers)
37 q.post_json(url,para,headers)
|