jupter
快捷鍵的使用
開啟幫助文件:
爬蟲的分類:
聚焦爬蟲:(資料解析)
增量式爬蟲:(資料的更新)
分布式爬蟲:
反爬機制:
反反爬策略
第乙個反爬機制:
requests模組的編碼流程:
回到資料夾所在位置,可以看到剛才爬取的網頁,開啟後看到的效果如下:# 匯入requests包
import requests
# 1.爬取搜狗首頁的頁面原始碼資料
url =
''response = requests.get(url=url)
page_text = response.text # text返回的是字串形式的響應資料
with
open
('./sogou.html'
,'w'
,encoding=
'utf-8'
)as fp:
fp.write(page_text)
# 2.簡易的網頁採集器
# 設計到的知識點:引數動態化,ua偽裝,亂碼的處理
word =
input
('enter a key word:'
)url =
'web'
# 引數動態化:將請求引數封裝成欄位作用到get方法的params引數中
params =
response = requests.get(url=url,params=params)
page_text = response.text
filename = word+
'.html'
with
open
(filename,
'w',encoding=
'utf-8'
)as fp:
fp.write(page_text)
(word,
)
處理完亂碼後,但是還是沒有出現想要的效果# 亂碼處理
word =
input
('enter a key word:'
)url =
'web'
# 引數動態化:將請求引數封裝成欄位作用到get方法的params引數中
params =
response = requests.get(url=url,params=params)
# 可以修改響應資料的編碼
response.encoding =
'utf-8'
# 手動修改了響應物件的編碼格式
page_text = response.text
filename = word+
'.html'
with
open
(filename,
'w',encoding=
'utf-8'
)as fp:
fp.write(page_text)
(word,
)
正常的訪問請求和異常的訪問請求的判別方式是什麼?
反爬機制:
反反爬策略:
get方法的返回值:import requests
# ua偽裝
word =
input
('enter a key word:'
)url =
'web'
# 引數動態化:將請求引數封裝成欄位作用到get方法的params引數中
params =
# ua偽裝
headers =
# 將偽裝的ua作用到了請求的請求頭中
response = requests.get(url=url,params=params,headers=headers)
# 可以修改響應資料的編碼
response.encoding =
'utf-8'
# 手動修改了響應物件的編碼格式
page_text = response.text
filename = word+
'.html'
with
open
(filename,
'w',encoding=
'utf-8'
)as fp:
fp.write(page_text)
(word,
)
- response
response的屬性:
Anaconda開發環境的自動部署
python專案中必須包含乙個 requirements.txt 檔案,用於記錄所有依賴包及其精確的版本號。以便新環境部署。1 在虛擬環境中使用pip生成 pip freeze requirements.txt2 當需要建立這個虛擬環境的完全副本,可以建立乙個新的虛擬環境,並在其上執行以下命令 pi...
Python開發環境 Anaconda搭建
在介紹anaconda之前,先介紹下conda,conda是乙個類似於pip pip3的可執行命令列工具,其核心功能是包的管理與環境管理,支援多種語言,因此用來管理python包也是綽綽有餘的。其與pip的區別是pip可以再任何環境中安裝python包,而 conda則可以再conda環境中安裝任何...
anaconda 環境搭建
spring cloud 實戰 乾貨 mybatis 實戰 乾貨 spring boot 實戰 乾貨 react 入門實戰 乾貨 構建中小型網際網路企業架構 乾貨 python 學習持續更新 elasticsearch 筆記 kafka storm 實戰 乾貨 scala 學習持續更新 rpc通過a...