"urllib.robotparser" --- robots.txt 的剖析器
********************************************

**原始碼：**Lib/urllib/robotparser.py

======================================================================

此模組 (module) 提供了一個單獨的類別 (class) "RobotFileParser"，它可以
知道某個特定 user agent（使用者代理）是否能在有發布 "robots.txt" 文件
的網站 fetch（擷取）特定 URL。有關 "robots.txt" 文件結構的更多細節，請
參閱 http://www.robotstxt.org/orig.html。

class urllib.robotparser.RobotFileParser(url='')

   此類別提供了一些方法可以讀取、剖析和回答關於 *url* 上的
   "robots.txt" 文件的問題。

   set_url(url)

      設置指向 "robots.txt" 文件的 URL。

   read()

      讀取 "robots.txt" URL 並將其輸入到剖析器。

   parse(lines)

      剖析 lines 引數。

   can_fetch(useragent, url)

      根據從 "robots.txt" 文件中剖析出的規則，如果 *useragent* 被允許
      fetch *url* 的話，則回傳 "True"。

   mtime()

      回傳最近一次 fetch "robots.txt" 文件的時間。這適用於需要定期檢查
      "robots.txt" 文件更新情況的長時間運行網頁爬蟲。

   modified()

      將最近一次 fetch "robots.txt" 文件的時間設置為當前時間。

   crawl_delay(useragent)

      針對指定的 *useragent* 從 "robots.txt" 回傳 "Crawl-delay" 參數的
      值。如果此參數不存在、不適用於指定的 *useragent* ，或是此參數在
      "robots.txt" 中所指的條目含有無效語法，則回傳 "None"。

      3.6 版新加入.

   request_rate(useragent)

      以 *named tuple* "RequestRate(requests, seconds)" 的形式從
      "robots.txt" 回傳 "Request-rate" 參數的內容。如果此參數不存在、
      不適用於指定的 *useragent* ，或是此參數在 "robots.txt" 中所指的
      條目含有無效語法，則回傳 "None"。

      3.6 版新加入.

   site_maps()

      以 "list()" 的形式從 "robots.txt" 回傳 "Sitemap" 參數的內容。如
      果此參數不存在或此參數在 "robots.txt" 中所指的條目含有無效語法，
      則回傳 "None"。

      3.8 版新加入.

下面的範例展示了 "RobotFileParser" 類別的基本用法：

   >>> import urllib.robotparser
   >>> rp = urllib.robotparser.RobotFileParser()
   >>> rp.set_url("http://www.musi-cal.com/robots.txt")
   >>> rp.read()
   >>> rrate = rp.request_rate("*")
   >>> rrate.requests
   3
   >>> rrate.seconds
   20
   >>> rp.crawl_delay("*")
   6
   >>> rp.can_fetch("*", "http://www.musi-cal.com/cgi-bin/search?city=San+Francisco")
   False
   >>> rp.can_fetch("*", "http://www.musi-cal.com/")
   True
