python - urllib RobotFileParser - robots.txt 中看似冲突的规则
问题描述
以下是 amazon.co.jp/robots.txt 的相关部分:
User-agent: *
Disallow: /-/
Disallow: /gp/aw/shoppingAids/
Allow: /-/en/
我要检查的 URL:"https://www.amazon.co.jp/-/en/035719/dp/B000H4W9WG/ref=sr_1_61?dchild=1&keywords=dot%20matrix%20printer&qid=1617229306&s=computers&sr=1-61"
现在,它符合 disallow:Disallow: /-/
也符合 allow: Allow: /-/en/
。
urllib 的 RobotFileParser 将 URL 标记为 can_fetch = False。我检查了源代码,它似乎是按时间顺序排列的。由于不允许首先出现,它将允许标记为 False,仅此而已。
知道这是否是考虑到 robots.txt 标准的正确方法,因为对我来说这似乎很违反直觉,并且认为应该允许该 url。
相关代码:
import urllib.robotparser
rp = urllib.robotparser.RobotFileParser()
rp.set_url("https://www.amazon.co.jp/robots.txt")
rp.read()
can_ftch = rp.can_fetch("*", "https://www.amazon.co.jp/-/en/035719/dp/B000H4W9WG/ref=sr_1_61?dchild=1&keywords=dot%20matrix%20printer&qid=1617229306&s=computers&sr=1-61")
编辑:按照谷歌标准,它应该像我一样工作。该 URL 应该是允许的。the most specific rule based on the length of the [path] entry trumps the less specific (shorter) rule
EIDT2:做了更多的挖掘,发现了这个 qoute:
对于 Google 和 Bing,规则是具有最多字符的指令获胜。在这里,这是禁止指令。
- 禁止:/blog/(6 个字符)
- 允许:/blog(5 个字符)
如果允许和禁止指令的长度相等,则限制最少的指令获胜。在这种情况下,这将是允许指令。
至关重要的是,这仅适用于 Google 和 Bing。其他搜索引擎听第一个匹配指令。在这种情况下,这是不允许的。
按照这个逻辑,RobotFileParser 确实是正确的。
解决方案
推荐阅读
- python-3.x - 更新的 Python to_csv 输出文件大小被放大
- xml - XSLT 从一个 HTML 表格中获取总计到另一个 HTML 表格中
- css - 使用过渡在加载时淡入图像
- python - 计算时间间隔
- java - 与 Apache Wicket 的 @MountPath 冲突
- oracle - 如何在 PL/SQL 块中打印游标?
- wpf - 如何在启动时打开第二个 WPF 窗口
- ios - 如何将一组(数组)图像保存到 Firebase 云存储中?
- html - 在加载之前在 iframe 上设置 webkit
- php - 为什么 PHP 论坛系统中的文件没有连接到其他文件?