我有以下 robots.txt
User-agent: *
Disallow: /images/
Sitemap: http://www.example.com/sitemap.xml
和下面的 robotsparser
def init_robot_parser(URL):
robot_parser = robotparser.RobotFileParser()
robot_parser.set_url(urlparse.urljoin(URL, "robots.txt"))
robot_parser.read()
return robot_parser
但是当我在上面 return robots_parser
执行 print robots_parser
时,我得到的只是
User-agent: *
Disallow: /images/
为什么它忽略站点地图行,我错过了什么吗?
最佳答案
Sitemap 是标准的扩展,robotparser 不支持它。您可以在the source中看到它只处理“用户代理”、“禁止”和“允许”。对于其当前功能(告诉您是否允许特定 URL),无需了解站点地图。
关于Python 的 robotsparser 忽略站点地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2978144/