Python知識分享網(wǎng) - 專業(yè)的Python學習網(wǎng)站 學Python,上Python222
requests模塊簡介及安裝
發(fā)布于:2023-10-29 20:16:56

2024 一天掌握python爬蟲【基礎(chǔ)篇】 涵蓋 requests、beautifulsoup、selenium

https://www.bilibili.com/video/BV1Ju4y1Y7k6/

 

Requests是一個優(yōu)秀的Http開發(fā)庫,支持HTTP連接保持和連接池,支持使用cookie保持會話,支持文件上傳,支持自動確定響應(yīng)內(nèi)容的編碼,支持國際化的 URL 和 POST 數(shù)據(jù)自動編碼等

開源地址:

https://github.com/psf/requests

中文官方文檔:

https://requests.readthedocs.io/projects/cn/zh_CN/latest/

 

request安裝:

pip install requests -i https://pypi.tuna.tsinghua.edu.cn/simple

 

helloWorld測試:

import requests

r = requests.get("http://www.baidu.com")
# 設(shè)置返回對象的編碼
r.encoding = "utf-8"
# 返回響應(yīng)狀態(tài)碼
print(r.status_code)
# 獲取網(wǎng)頁內(nèi)容
print(r.text)
# 查看返回對象類型
print(type(r))

 

轉(zhuǎn)載自: