1. 程式人生 > >爬蟲Robots協議

爬蟲Robots協議

 Robots協議就是每個網站對於來到的爬蟲所提出的要求。(並非強制要求遵守的協議,只是一種建議,但是如果不遵守有可能會承擔法律責任。)
 每個網站的Robots協議都在該網站的根目錄下,例如百度的Robots協議的位置就是’https://www.baidu.com/robots.txt’ 或者京東的Robots協議就在’https://www.jd.com/robots.txt
下面給出一段京東的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: /

第一個的意思就是說對於所有的爬蟲,不能爬取在/?開頭的路徑,也不能訪問和/pop/*.html 匹配的路徑。
後面四個使用者代理的爬蟲不允許訪問任何資源。

所以Robots協議的基本語法如下:

User-agent: 這裡是爬蟲的名字
Disallow: /該爬蟲不允許訪問的內容