第一記:環境搭建

使用環境: python 3.6 + pycharm 5.0.3 + requests 1. pip 安裝 requests 安裝命令:pip install requests 卸載命令:pip uninstall requests 2.requests 中文官網地址: http://docs.python-requests.org/zh_CN/latest/ 3.一個簡單的get請求實例 import requests url = "https://www.cnblogs.com/CS-zhanglu/" r = requests.get(url) print(r.text) 4.response的返回內容還有其它更多信息 -- r.status_code     #響應狀態碼 -- r.content           #字節方式的響應體,會自動爲你解碼 gzip 和 deflate 壓縮 -- r.headers          #以字典對象存儲服務器響應頭,可是這個字典比較特殊,字典鍵不區分大小寫,若鍵不存在則返回None -- r.json()             #Requests中內置的JSON解碼器 ,json轉成python的字典了 -- r.url                  # 獲取url -- r.encoding         # 編碼格式 -- r.cookies           # 獲取cookie -- r.text               #字符串方式的響應體,會自動根據響應頭部的字符編碼進行解碼 -- r.raise_for_status() #失敗請求(非200響應)拋出異常
相關文章
相關標籤/搜索