【发布时间】:2013-03-11 16:58:42
【问题描述】:
我正在编写一个爬虫,为此我正在实现 robots.txt 解析器,我正在使用标准库 robotparser。
robotparser 似乎没有正确解析,我正在使用 Google 的 robots.txt 调试我的爬虫。
(以下示例来自 IPython)
In [1]: import robotparser
In [2]: x = robotparser.RobotFileParser()
In [3]: x.set_url("http://www.google.com/robots.txt")
In [4]: x.read()
In [5]: x.can_fetch("My_Crawler", "/catalogs") # This should return False, since it's on Disallow
Out[5]: False
In [6]: x.can_fetch("My_Crawler", "/catalogs/p?") # This should return True, since it's Allowed
Out[6]: False
In [7]: x.can_fetch("My_Crawler", "http://www.google.com/catalogs/p?")
Out[7]: False
这很有趣,因为有时它似乎“工作”,有时它似乎失败了,我也尝试了来自 Facebook 和 Stackoverflow 的 robots.txt。这是来自robotpaser 模块的错误吗?还是我在这里做错了什么?如果有,是什么?
我想知道this bug 是否有任何相关的东西
【问题讨论】:
-
我也在 Linux 机器(Arch Linux)上使用 Python 2.7.3
标签: python python-2.7 web-crawler robots.txt