Max*_*Max 6 python robots.txt scrapy
Scrapy 框架有 RobotsTxtMiddleware。它需要确保 Scrapy 尊重 robots.txt。它需要在设置ROBOTSTXT_OBEY = True
中设置,然后 Scrapy 会尊重 robots.txt 策略。我做到了并运行了蜘蛛。在调试中,我看到了对http://site_url/robot.txt 的请求。
robot.txt
间谍程序要求规则所在,这是正常的。
robot.txt
基本上是一个您不应该访问/抓取的网址黑名单,它使用 glob/regex 类型的语法来指定禁止的网址。
Scapy 将读取robot.txt
这些规则并将其翻译为代码。在抓取过程中,当间谍程序遇到某个 URL 时,它首先会根据从 URL 生成的规则来验证robot.txt
该 URL 是否可以访问。如果 URL 没有被robot.txt
scrapy 列入黑名单,则会访问该 url 并传递一个Response
.
robot.txt
不仅将网址列入黑名单,还提供抓取发生的速度。这是一个例子robot.txt
:
User-Agent: *
Disallow: /x?
Disallow: /vote?
Disallow: /reply?
Disallow: /submitted?
Disallow: /submitlink?
Disallow: /threads?
Crawl-delay: 30
Run Code Online (Sandbox Code Playgroud)