首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么robots.txt的含量在手工访问时以及通过ChromeDriver和Chrome通过Selenium访问时有所不同?

问为什么robots.txt的含量在手工访问时以及通过ChromeDriver和Chrome通过Selenium访问时有所不同?
EN

Stack Overflow用户
提问于 2019-03-22 00:34:19
回答 1查看 1.1K关注 0票数 1

我正在努力尊重robots.txt文件,当我在网络上爬行时,我遇到了一些奇怪的事情。我要访问的robots.txt URL是:https://podatki.gov.si/robots.txt

如果我在Chrome中打开这个链接,我会得到这个链接:

代码语言:javascript
复制
User-agent: *
Disallow: /

但是,如果我使用Internet或Selenium WebDriver (ChromeDriver)打开此链接,则会得到以下内容:

代码语言:javascript
复制
#
# robots.txt
#
# This file is to prevent the crawling and indexing of certain parts
# of your site by web crawlers and spiders run by sites like Yahoo!
# and Google. By telling these "robots" where not to go on your site,
# you save bandwidth and server resources.
#
# This file will be ignored unless it is at the root of your host:
# Used:    http://example.com/robots.txt
# Ignored: http://example.com/site/robots.txt
#
# For more information about the robots.txt standard, see:
# http://www.robotstxt.org/robotstxt.html

User-agent: *
Crawl-delay: 10
# CSS, JS, Images
Allow: /misc/*.css$
Allow: /misc/*.css?
Allow: /misc/*.js$
Allow: /misc/*.js?
Allow: /misc/*.gif
Allow: /misc/*.jpg
Allow: /misc/*.jpeg
Allow: /misc/*.png
Allow: /modules/*.css$
Allow: /modules/*.css?
Allow: /modules/*.js$
Allow: /modules/*.js?
Allow: /modules/*.gif
Allow: /modules/*.jpg
Allow: /modules/*.jpeg
Allow: /modules/*.png
Allow: /profiles/*.css$
Allow: /profiles/*.css?
Allow: /profiles/*.js$
Allow: /profiles/*.js?
Allow: /profiles/*.gif
Allow: /profiles/*.jpg
Allow: /profiles/*.jpeg
Allow: /profiles/*.png
Allow: /themes/*.css$
Allow: /themes/*.css?
Allow: /themes/*.js$
Allow: /themes/*.js?
Allow: /themes/*.gif
Allow: /themes/*.jpg
Allow: /themes/*.jpeg
Allow: /themes/*.png
# Directories
Disallow: /includes/
Disallow: /misc/
Disallow: /modules/
Disallow: /profiles/
Disallow: /scripts/
Disallow: /themes/
# Files
Disallow: /CHANGELOG.txt
Disallow: /cron.php
Disallow: /INSTALL.mysql.txt
Disallow: /INSTALL.pgsql.txt
Disallow: /INSTALL.sqlite.txt
Disallow: /install.php
Disallow: /INSTALL.txt
Disallow: /LICENSE.txt
Disallow: /MAINTAINERS.txt
Disallow: /update.php
Disallow: /UPGRADE.txt
Disallow: /xmlrpc.php
# Paths (clean URLs)
Disallow: /admin/
Disallow: /comment/reply/
Disallow: /filter/tips/
Disallow: /node/add/
Disallow: /search/
Disallow: /user/register/
Disallow: /user/password/
Disallow: /user/login/
Disallow: /user/logout/
# Paths (no clean URLs)
Disallow: /?q=admin/
Disallow: /?q=comment/reply/
Disallow: /?q=filter/tips/
Disallow: /?q=node/add/
Disallow: /?q=search/
Disallow: /?q=user/password/
Disallow: /?q=user/register/
Disallow: /?q=user/login/
Disallow: /?q=user/logout/

这一切为什么要发生?后者似乎是一个通用的robots.txt文件,也许是自动生成的?

EN

回答 1

Stack Overflow用户

发布于 2019-03-22 09:30:36

我观察到同样的行为如下:

  • 当手动访问网页https://podatki.gov.si/robots.txt时,我得到: 用户代理:*不允许:/
  • 当使用ChromeDriver和Chrome访问网页ChromeDriver时,I got:# robots.txt ##这个文件是为了防止由雅虎和谷歌等网站运行的网页爬虫和蜘蛛爬行和索引网站#的某些部分。通过告诉这些“机器人”不要去你的网站,#你节省了带宽和服务器资源。#这个文件将被忽略,除非它位于您的主机的根部:#User:http://example.com/robots.txt #已被忽略:http://example.com/site/robots.txt ##有关robots.txt标准的更多信息,请参见:# http://www.robotstxt.org/robotstxt.html用户-代理:*Crawl: 10 # CSS,JS,图片允许:/misc/*CSS$robots.txt: /misc/*.css?允许:/misc/*..js$.js: /misc/*.js?允许:/misc/*..gif允许:/misc/*..jpg允许:/misc/*..jpeg允许:/misc/*..png允许:/模块/*..css$允许://.css/*..css?允许:/模块/*..js$ Allow: /modules/*..js?允许:/模块/*..gif允许:/模块/*..jpg允许:/模块/*..jpeg允许:/模块/*..png允许:/profile/*..css$.css://profile/*..css?允许:/profile/*..js$.js:/profile/*.js?允许:/profile/*..gif允许:/profile/*..jpg允许:/profile/*..jpeg允许:/profile/*..png允许:/themes/*..css$ALLO许可: /themes/*.css?允许: /themes/*.js$ Allow: /themes/*.js?..gif允许:/主题/*..jpg允许:/主题/*..jpeg允许:/ /cron.php /*..png#目录允许:/包含/不允许:/模块/不允许:/配置文件/不允许:/脚本/不允许:/主题/文件不允许:/cron.php禁用: /INSTALL.mysql.txt不允许: /INSTALL.pgsql.txt不允许: /INSTALL.sqlite.txt禁用:/install.php不允许: /INSTALL.txt不允许: /LICENSE.txt不允许: /MAINTAINERS.txt不允许:/ /update.php /注册/不允许://update.php/密码/禁用://user/登录/不允许://user/注销://user/注销/#路径(没有干净的URL)不允许: /?q=admin/禁用:/?q=注释/应答/禁用:/?q=筛选/提示/不允许:/?q=节点/添加/不允许:/?q=搜索/不允许:/?q=用户/密码/禁用:/?q=用户/注册/不允许:/?q=用户/登录/禁用:/?q=用户/注销/

robots.txt

根据robotstxt.org网站所有者使用robots.txt文件向网络机器人提供关于他们的网站的指示。这被称为--机器人排除协议。

它的工作如下:

  • 机器人想要访问一个网站网址,例如http://www.example.com/welcome.html。
  • 在这样做之前,它首先检查http://www.example.com/robots.txt,并发现: 用户代理:*不允许:/
代码语言:javascript
复制
- The **`User-agent: *`** means this section applies to all robots. 
- The **`Disallow: /`** tells the robot that it should not visit any pages on the site.

​

在使用robots.txt时有两个重要的注意事项

  • 机器人可以忽略你的robots.txt。特别是扫描网络安全漏洞的恶意软件机器人,以及垃圾邮件发送者使用的电子邮件地址收割机将不予注意。
  • robots.txt文件是一个公开可用的文件。任何人都可以看到您不希望机器人使用的服务器中的哪些部分。

欧特罗

由于使用ChromeDriver和Chrome,navigator.webdriver为合作用户代理定义了一种标准方式,用于通知文档由WebDriver控制,以便在自动化过程中触发备用代码路径。因此,您可以从robots.txt中看到更多的内容。

您可以在Selenium flag驱动程序:修改navigator.webdriver标志以防止硒检测中找到相关的讨论

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55291206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档