1.get請求:不攜帶引數的get請求
不攜帶引數的get請求 + headers
攜帶引數的get請求 + headers
2.post請求: 構建引數的post請求
3.響應資料的獲取與屬性
(1).響應資料的獲取:
res.text: 文字資料
res.json(): json資料
res.content: 流
(2).向應的其他屬性:
res.status_code: 獲取響應狀態碼
res.headers: 響應頭
res.cookie: cookie資訊
requests模組的get請求
#不攜帶引數的get請求: 爬取搜狗主頁
import
requests
url = '
'res = requests.get(url=url)
(res)
(res.text)
with open(
'sougou.html
', '
w', encoding='
utf-8
') as f:
f.write(res.text)
#不攜帶引數的get請求 + headers: 爬取知乎的發現頁
import
requests
headers =
url = '
'res = requests.get(url=url, headers=headers)
with open(
'zhihu.html
', '
w', encoding='
utf-8
') as f:
f.write(res.text)
#攜帶引數的get請求 + headers: 知乎的發現欄中搜尋python
import
requests
headers =
url= '
'params =
res = requests.get(url=url, headers=headers, params=params)
(res)
(res.text)
with open(
'python.html
', '
w', encoding='
utf-8
') as f:
f.write(res.text)
重點掌握get & post: get與post的區別1、get請求中的引數包含在url裡面,資料可以在url中看到,而post請求的url不回包含這些資料,post的資料
都是通過表單形式傳輸的。會包含在請求體中
2、get請求提交的資料最多只有1024位元組,而post方式沒有限制
3、post請求比get請求相對安全
requests模組的post請求
#requests的post請求: 以post方式請求httpbin.org/post時會返回提交的請求資訊
import
requests
headers =
url = '
'data =
res = requests.post(url=url, headers=headers, data=data)
print(res.text)
Get請求 Post請求
複製直接用 post同步請求 void synchronourequestbypost post非同步請求 1.方法 void asynchronourequestbypost void connection nsurlconnection connection didreceiveresponse...
get請求 post請求
今天由於群裡的人說出了這個問題,在這裡總結一下,順便加強記憶。get和post是http請求的兩種基本方法,要說它們的區別 直觀的區別就是get把引數包含在url中,post通過request body傳遞引數 本標準答案參考自w3schools 這只是乙個表面的並不是深層的更深一步理解 get和p...
POST 請求 GET請求
get 引數 username 和 password 1.get的請求都拼接在url中 2.後面是跟的引數 前面跟的都是介面 3.引數的形式key value key2 value2 對於get請求 所有得引數都拼接在url中,這樣暴露在外面 會造成資料的不安全 url的長度是有限制的 如果引數過於...