【问题标题】:Why are the contents of robots.txt different when accessed manually and through ChromeDriver and Chrome through Selenium为什么手动访问和通过 ChromeDriver 和 Chrome 通过 Selenium 访问时 robots.txt 的内容不同
【发布时间】:2019-08-12 22:39:18
【问题描述】:

我试图尊重 robots.txt 文件,同时进行网络爬网,但遇到了一些奇怪的事情。我试图访问的 robots.txt URL 是:https://podatki.gov.si/robots.txt

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

User-agent: *
Disallow: /

但如果我使用 Internet Explorer 或 Selenium WebDriver (ChromeDriver) 打开此链接,我会得到:

#
# 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 文件,可能是自动生成的?

【问题讨论】:

  • 我用 chrome 打开它,得到了更大的。

标签: selenium google-chrome web-crawler selenium-chromedriver robots.txt


【解决方案1】:

我观察到以下相同的行为:

  • 当访问网页https://podatki.gov.si/robots.txt手动,我得到:

    User-agent: *
    Disallow: /
    
  • 当使用 ChromeDriverChrome 访问网页 https://podatki.gov.si/robots.txt 时,我得到:

    #
    # 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

根据robotstxt.org,网站所有者使用robots.txt 文件向网络机器人提供有关其网站的说明。这称为机器人排除协议

它的工作原理如下:

  • 机器人想要访问网站 URL,例如http://www.example.com/welcome.html
  • 在此之前,它首先检查http://www.example.com/robots.txt,然后找到:

    User-agent: *
    Disallow: /
    
    • User-agent: * 表示本节适用于所有机器人。
    • Disallow: / 告诉机器人它不应访问网站上的任何页面。

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

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

结尾

在使用 ChromeDriverChrome 时,navigator.webdriver 定义了一种标准方式,用于合作 用户代理 来通知文档它是由 WebDriver 控制,因此可以在自动化期间触发备用代码路径。因此,您可以从robots.txt 看到更多内容。

您可以在Selenium webdriver: Modifying navigator.webdriver flag to prevent selenium detection找到相关讨论

【讨论】:

  • 我不太确定我是否理解你的结论。浏览器和 selenium 驱动程序只检索 robots.txt 文件,不做任何其他事情。所以你不能说 robots.txt 文件被忽略了。他们检索它,但在某些情况下它是不同的。这就是我的问题所在。
  • @kozeljko 查看我的答案更新,让我知道你的想法
猜你喜欢
  • 2015-03-21
  • 2016-05-06
  • 2019-12-06
  • 1970-01-01
  • 1970-01-01
  • 2011-01-16
  • 1970-01-01
  • 1970-01-01
  • 2011-05-27
相关资源
最近更新 更多