搜索引擎蜘蛛及網站robots.txt文件詳解[轉載]

咱們知道,搜索引擎都有本身的「搜索機器人」(ROBOTS),並經過這些ROBOTS在網絡上沿着網頁上的連接(通常是http和src連接)不斷抓取資料創建本身的數據庫。

對於網站管理者和內容提供者來講,有時候會有一些站點內容,不但願被ROBOTS抓取而公開。爲了解決這個問題,ROBOTS開發界提供了兩個辦法:一個是robots.txt,另外一個是TheRobotsMETA標籤。

注意:robots.txt寫法是否正確對搜索引擎抓取網站相當重要,咱們儘可能按照標準的格式寫語句,不然出現的錯誤可能會致使搜索引擎不能正常爬行站點;咱們能夠經過google sitemap中的robots.txt檢測工具來檢查網站上是否存在robots.txt文件以及該文件寫法是否正確

1、robots.txt

一、什麼是robots.txt?

robots.txt是一個純文本文件,經過在這個文件中聲明該網站中不想被robots訪問的部分,這樣,該網站的部分或所有內容就能夠不被搜索引擎收錄了,或者指定搜索引擎只收錄指定的內容。

當一個搜索機器人訪問一個站點時,它會首先檢查該站點根目錄下是否存在robots.txt,若是找到,搜索機器人就會按照該文件中的內容來肯定訪問的範圍,若是該文件不存在,那麼搜索機器人就沿着連接抓取。

robots.txt必須放置在一個站點的根目錄下,並且文件名必須所有小寫

網站URL
相應的robots.txt的URL

http://www.w3.org/
http://www.w3.org/robots.txt

http://www.w3.org:80/
http://www.w3.org:80/robots.txt

二、robots.txt的語法

"robots.txt"文件包含一條或更多的記錄,這些記錄經過空行分開(以CR,CR/NL,orNL做爲結束符),在該文件中可使用#進行註解,具體使用方法和UNIX中的慣例同樣。該文件中的記錄一般以一行或多行User-agent開始,後面加上若干Disallow行,詳細狀況以下:

User-agent:
該項的值用於描述搜索引擎robot的名字,在"robots.txt"文件中,若是有多條User-agent記錄說明有多個robot會受到該協議的限制,對該文件來講,至少要有一條User-agent記錄。若是該項的值設爲*,則該協議對任何機器人均有效,在"robots.txt"文件中,"User-agent:*"這樣的記錄只能有一條。關於搜索引擎robots的名字,請參考文章"搜索引擎蜘蛛程序名稱大全"

Disallow:
該項的值用於描述不但願被訪問到的一個URL,這個URL能夠是一條完整的路徑,也能夠是部分的,任何以Disallow開頭的URL均不會被robot訪問到。例如"Disallow:/help"對/help.html和/help/index.html都不容許搜索引擎訪問,而"Disallow:/help/"則容許robot訪問/help.html,而不能訪問/help/index.html

任何一條Disallow記錄爲空,說明該網站的全部部分都容許被訪問,在"robots.txt"文件中,至少要有一條Disallow記錄。若是"robots.txt"是一個空文件,則對於全部的搜索引擎robot,該網站都是開放的


下面是一些robots.txt基本的用法:

禁止全部搜索引擎訪問網站的任何部分:
User-agent: *
Disallow: /

容許全部的robot訪問
User-agent: *
Disallow:
或者也能夠建一個空文件:robots.txt

禁止全部搜索引擎訪問網站的幾個部分(下例中的cgi-bin、tmp、private目錄)
User-agent: *
Disallow: /cgi-bin/
Disallow: /tmp/
Disallow: /private/

禁止某個搜索引擎的訪問(下例中的BadBot)
User-agent: BadBot
Disallow: /

只容許某個搜索引擎的訪問(下例中的WebCrawler)
User-agent: WebCrawler
Disallow:


三、常見搜索引擎機器人Robots名字

名稱搜索引擎         URL

Baiduspider             http://www.baidu.com

Scooter                   http://www.altavista.com

ia_archiver              http://www.alexa.com

Googlebot               http://www.google.com

Inktomi Slurp          http://www.yahoo.com

FAST-WebCrawler  http://www.alltheweb.com

Slurp                       http://www.inktomi.com

MSNbot                   http://search.msn.com


四、robots.txt舉例

下面是一些著名站點的robots.txt:

http://www.google.com/robots.txt

http://www.ibm.com/robots.txt

http://www.sun.com/robots.txt

http://www.eachnet.com/robots.txt

看看百度的robots.txt:http://www.baidu.com/robots.txt

黑色夢中SEO博客的robots.txt文件:http://www.bloghuman.com/robots.txt


五、常見robots.txt錯誤

·顛倒了順序:
錯誤寫成
User-agent: *
Disallow: GoogleBot

正確的應該是:
User-agent:GoogleBot
Disallow: /

·把多個禁止命令放在一行中:
例如,錯誤地寫成
Disallow:/css//cgi-bin//images/

正確的應該是
Disallow:/css/
Disallow:/cgi-bin/
Disallow:/images/

·行前有大量空格
例如寫成
  Disallow:/cgi-bin/
儘管在標準沒有談到這個,可是這種方式很容易出問題。

·404重定向到另一個頁面:
當Robot訪問不少沒有設置robots.txt文件的站點時,會被自動404重定向到另一個Html頁面。這時Robot經常會以處理robots.txt文件的方式處理這個Html頁面文件。雖然通常這樣沒有什麼問題,可是最好能放一個空白的robots.txt文件在站點根目錄下

·採用大寫
USER-AGENT:EXCITE
DISALLOW:
雖然標準是沒有大小寫的,可是目錄和文件名應該小寫,:
User-agent:GoogleBot
Disallow:

·語法中只有Disallow,沒有Allow!
錯誤的寫法是:
User-agent: Baiduspider
Disallow: /john/
Allow: /jane/

·忘記了斜槓/
錯誤的寫作:
User-agent: Baiduspider
Disallow: css

正確的應該是
User-agent: Baiduspider
Disallow: /css/

下面一個小工具專門檢查robots.txt文件的有效性:

http://www.searchengineworld.com/cgi-bin/robotcheck.cgi


2、Robots Meta標籤

一、什麼是Robots Meta標籤

Robots.txt文件主要是限制整個站點或者目錄的搜索引擎訪問狀況,而Robots Meta標籤則主要是針對一個個具體的頁面。和其餘的META標籤(如使用的語言、頁面的描述、關鍵詞等)同樣,Robots Meta標籤也是放在頁面的中,專門用來告訴搜索引擎ROBOTS如何抓取該頁的內容。


二、Robots Meta標籤的寫法:

Robots Meta標籤中沒有大小寫之分,name=」Robots」表示全部的搜索引擎,能夠針對某個具體搜索引擎寫爲name=」BaiduSpider」。content部分有四個指令選項:index、noindex、follow、nofollow,指令間以「,」分隔。

index指令告訴搜索機器人抓取該頁面;

follow指令表示搜索機器人能夠沿着該頁面上的連接繼續抓取下去;

Robots Meta標籤的缺省值是index和follow,只有inktomi除外,對於它,缺省值是index、nofollow。


須要注意的是:上述的robots.txt和Robots Meta標籤限制搜索引擎機器人(ROBOTS)抓取站點內容的辦法只是一種規則,須要搜索引擎機器人的配合才行,並非每一個ROBOTS都遵照的。


目前看來,絕大多數的搜索引擎機器人都遵照robots.txt的規則,而對於RobotsMETA標籤,目前支持的並很少,可是正在逐漸增長,如著名搜索引擎GOOGLE就徹底支持,並且GOOGLE還增長了一個指令「archive」,能夠限制GOOGLE是否保留網頁快照。例如:

表示抓取該站點中頁面並沿着頁面中連接抓取,可是不在GOOLGE上保留該頁面的網頁快照。

例子:
#robots,scram


css

User-agent:*
Disallow:/cgi-bin
Disallow:/TRANSCRIPTS
Disallow:/development
Disallow:/third
Disallow:/beta
Disallow:/java
Disallow:/shockwave
Disallow:/JOBS
Disallow:/pr
Disallow:/Interactive
Disallow:/alt_index.html
Disallow:/webmaster_logs
Disallow:/newscenter
Disallow:/virtual
Disallow:/DIGEST
Disallow:/QUICKNEWS
Disallow:/SEARCH




User-agent:Mozilla/3.01(hotwired-test/0.1)
Disallow:/cgi-bin
Disallow:/TRANSCRIPTS
Disallow:/development
Disallow:/third
Disallow:/beta
Disallow:/java
Disallow:/shockwave
Disallow:/JOBS
Disallow:/pr
Disallow:/Interactive
Disallow:/alt_index.html
Disallow:/webmaster_logs
Disallow:/newscenter
Disallow:/virtual
Disallow:/DIGEST
Disallow:/QUICKNEWS
Disallow:/SEARCH




User-agent:Slurp
Disallow:/cgi-bin
Disallow:/TRANSCRIPTS
Disallow:/development
Disallow:/third
Disallow:/beta
Disallow:/java
Disallow:/shockwave
Disallow:/JOBS
Disallow:/pr
Disallow:/Interactive
Disallow:/alt_index.html
Disallow:/webmaster_logs
Disallow:/newscenter
Disallow:/virtual
Disallow:/DIGEST
Disallow:/QUICKNEWS
Disallow:/SEARCH
User-agent:Scooter
Disallow:/cgi-bin
Disallow:/TRANSCRIPTS
Disallow:/development
Disallow:/third
Disallow:/beta
Disallow:/java
Disallow:/shockwave
Disallow:/JOBS
Disallow:/pr
Disallow:/Interactive
Disallow:/alt_index.html
Disallow:/webmaster_logs
Disallow:/newscenter
Disallow:/virtual
Disallow:/DIGEST
Disallow:/QUICKNEWS
Disallow:/SEARCH




User-agent:Ultraseek
Disallow:/cgi-bin
#Disallow:/TRANSCRIPTS
Disallow:/development
Disallow:/third
Disallow:/beta
Disallow:/java
Disallow:/shockwave
Disallow:/JOBS
Disallow:/pr
Disallow:/Interactive
Disallow:/alt_index.html
Disallow:/webmaster_logs
Disallow:/newscenter
Disallow:/virtual
Disallow:/DIGEST
Disallow:/QUICKNEWS
Disallow:/SEARCH





User-agent:smallbear Disallow:/cgi-bin Disallow:/java Disallow:/images Disallow:/development Disallow:/third Disallow:/beta Disallow:/webmaster_logs Disallow:/virtual Disallow:/shockwave Disallow:/TRANSCRIPTS Disallow:/newscenter Disallow:/virtual Disallow:/DIGEST Disallow:/QUICKNEWS Disallow:/SEARCH Disallow:/alt_index.html User-agent:GoogleBot Disallow:/cgi-bin Disallow:/java Disallow:/images Disallow:/development Disallow:/third Disallow:/beta Disallow:/webmaster_logs Disallow:/virtual Disallow:/shockwave Disallow:/TRANSCRIPTS Disallow:/newscenter Disallow:/virtual Disallow:/DIGEST Disallow:/QUICKNEWS Disallow:/SEARCH Disallow:/alt_index.html
相關文章
相關標籤/搜索