前言
上一節學習了requests庫,這一節學習robots協定
限制爬蟲的方法
- 審查爬蟲來源,需要網站作者有一定的程式設計基礎
- 聲明robots協定,一般放在網站的根目錄下,robots.txt檔案
京東robots協定
京東robots連結
User-agent: *
Disallow: /?*
Disallow: /pop/.html
Disallow: /pinpai/.html?*
User-agent: EtaoSpider
Disallow: /
User-agent: HuihuiSpider
Disallow: /
User-agent: GwdangSpider
Disallow: /
User-agent: WochachaSpider
Disallow: /
其他robots協定
百度robots協定
新浪robots協定
qq的robots協定
qq新聞robots協定
國家教育部無robots協定
網站不提供robots協定則全網可以随意爬取
robots協定的使用
- 任意爬蟲檔案應該可以自動識别robots.txt檔案
- 不遵守爬蟲協定則可能面臨法律風險
- 低頻率的爬蟲通路網站是允許的,但不可商用
總結
爬蟲協定說明:
User-angent: *表示所有使用者
Disallow:/表示所有目錄不可爬取