import requests
print("*****************一般性Http请求*******************")
r = requests.get('https://www.baidu.com/')
print('HttpStatus:%d' %(r.status_code))
print('Encoding:%s' %(r.encoding))
print(r.content)
print("*****************JSON获取*******************")
r = requests.get('https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20%3D%202151330&format=json')
print(r.json())
print("*****************传入特殊请求头*****************")
r = requests.get('https://www.douban.com/', headers={'User-Agent':
'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit'})
print(r.text)
print("*****************发送POST请求*****************")
r = requests.post('https://accounts.douban.com/login',
data={'form_email': 'abc@example.com', 'form_password': '123456'})
print(r.text)
print("*****************发送JSON请求*****************")
params = {'key': 'value'}
cookieStr = {'JSESSIONID': '098'}
r = requests.post("url", json=params, cookies=cookieStr, timeout=5)
print(r.headers)
activityInfo =r.json()
print(activityInfo['res_data'][-1]['name'])