亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

這是我寫的python3的版本, 歡迎大家參考和指正

代碼部分:

import?requests


def?url_simple_demo(URL_STR):
????response?=?requests.get(URL_STR)
????print('>>>>>>?headers:')
????print(response.headers)
????print('>>>>>>?body:')
????#?print(response.json())??#?json方法的速度比text快
????print(response.text)
????return


def?url_get_demo(URL_STR):
????url_param?=?{'param1':?'hello',?'param2':?'world'}
????response?=?requests.get(URL_STR,?params=url_param)
????print('>>>>>>?status:?%s?%s'?%?(response.status_code,?response.reason))
????print('>>>>>>?headers:')
????print(response.headers)
????print('>>>>>>?body:')
????#?print(response.json())
????print(response.text)
????return


if?__name__?==?'__main__':
????URL_IP?=?'http://httpbin.org/ip'
????url_simple_demo(URL_IP)

????print('-------分割線-------\n')
????URL_GET?=?'http://httpbin.org/get'
????url_get_demo(URL_GET)


輸出結果:

>>>>>>?headers:
{'Connection':?'keep-alive',?'Server':?'meinheld/0.6.1',?'Date':?'Sat,?12?Aug?2017?12:03:43?GMT',?'Content-Type':?'application/json',?'Access-Control-Allow-Origin':?'*',?'Access-Control-Allow-Credentials':?'true',?'X-Powered-By':?'Flask',?'X-Processed-Time':?'0.000636100769043',?'Content-Length':?'31',?'Via':?'1.1?vegur'}
>>>>>>?body:
{
??"origin":?"127.0.0.1"
}

-------分割線-------

>>>>>>?status:?200?OK
>>>>>>?headers:
{'Connection':?'keep-alive',?'Server':?'meinheld/0.6.1',?'Date':?'Sat,?12?Aug?2017?12:03:44?GMT',?'Content-Type':?'application/json',?'Access-Control-Allow-Origin':?'*',?'Access-Control-Allow-Credentials':?'true',?'X-Powered-By':?'Flask',?'X-Processed-Time':?'0.00121283531189',?'Content-Length':?'340',?'Via':?'1.1?vegur'}
>>>>>>?body:
{
??"args":?{
????"param1":?"hello",?
????"param2":?"world"
??},?
??"headers":?{
????"Accept":?"*/*",?
????"Accept-Encoding":?"gzip,?deflate",?
????"Connection":?"close",?
????"Host":?"httpbin.org",?
????"User-Agent":?"python-requests/2.18.2"
??},?
??"origin":?"127.0.0.1",?
??"url":?"http://httpbin.org/get?param1=hello&param2=world"
}


正在回答

2 回答

666

1 回復 有任何疑惑可以回復我~
#1

喵_17 提問者

賺賺積分, 嘿嘿嘿
2017-08-18 回復 有任何疑惑可以回復我~

哈哈。有幫到我

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Python-走進Requests庫
  • 參與學習       38700    人
  • 解答問題       114    個

python類庫中,requests是一件利器,想深入了解一起來學吧

進入課程

這是我寫的python3的版本, 歡迎大家參考和指正

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號