gpt4 book ai didi

Python 的 robotparser 忽略站点地图

转载 作者:太空宇宙 更新时间:2023-11-03 23:49:29 24 4
gpt4 key购买 nike

我有以下 robots.txt

User-agent: *
Disallow: /images/
Sitemap: http://www.example.com/sitemap.xml

和下面的robotparser

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 robot_parser 上面执行 print robot_parser 时,我得到的只是

User-agent: *
Disallow: /images/

为什么它会忽略 Sitemap 行,我是不是遗漏了什么?

最佳答案

Sitemap 是标准的扩展,robotparser 不支持它。你可以在the source中看到它只处理“用户代理”、“禁止”和“允许”。对于其当前功能(告诉您是否允许特定 URL),无需了解 Sitemap。

关于Python 的 robotparser 忽略站点地图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2978144/

24 4 0
文章推荐: html - 为交替的
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com