一、Requests庫的安裝
以管理員身份運行命令控制臺,輸入?
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple requests
測試:打開IDLE
此時百度的html頁面被抓取成功
二、requests庫的7個主要方法
三、Requests庫的get()方法:獲得一個網(wǎng)頁
完整使用方法:
Requests庫的get()方法源代碼:get方法實際上使用request方法來封裝, 也就是說,除了request方法是基礎方法,其他6個方法都是通過調(diào)用request方法實現(xiàn)的,即實際上只有一個方法。
四、Requests庫的2個主要對象
?下面重點來看Response對象:
Response 對象包含服務器返回的所有信息,還包含了向服務器請求的request信息
Response對象的5個常用屬性:
?
五、使用get()方法獲取頁面內(nèi)容的基本流程
關于Requests的編碼:?
?ISO-8859-1不能解析中文,apparent_encoding比encoding更加準確,因為encoding并沒有分析內(nèi)容。所以,一般用encoding不能正確解析中文頁面內(nèi)容時,用apparent_encoding的值替換encoding文章來源:http://www.zghlxwxcb.cn/news/detail-719168.html
?文章來源地址http://www.zghlxwxcb.cn/news/detail-719168.html
到了這里,關于網(wǎng)絡爬蟲-Requests庫入門的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!