【问题标题】:Prevent WGET and other automated downloading of website防止 WGET 和其他网站自动下载
【发布时间】:2019-07-27 19:28:18
【问题描述】:

我有一个 PHP 站点。 最近几周,我的网站从一个位置获得了大量自动点击。 这表明有人正在以自动方式“偷猎”内容,而不是通过适当的浏览器访问该站点。我想这是由 WGET(或 CURL 或其他)等工具/实用程序完成的。

有没有办法阻止这种自动访问?

为了进行调查,我尝试在雅虎、美国新闻和彭博等流行网站上使用 WGET,WGET 实用程序成功地从雅虎和美国新闻下载了页面(HTML 代码)。但是,在彭博示例页面上的类似尝试失败了。

我使用的命令:

wget64.exe https://www.bloomberg.com/research//stocks/snapshot/snapshot_article.asp?ticker=CWEN

保存的结果文件具有以下内容:

<h2 class="main__heading">We've detected unusual activity from your computer network</h2>

    <p class="continue">To continue, please click the box below to let us know you're not a robot.</p>
    <div id="px-captcha"></div>
</section>
<section class="box">
    <section class="info">
        <h3 class="info__heading">Why did this happen?</h3>
        <p class="info__text">Please make sure your browser supports JavaScript and cookies and that you are not blocking them from loading. For more information you can review our <a class="info__link" href="/notices/tos">Terms of Service</a> and <a class="info__link" href="/notices/tos">Cookie Policy</a>

这表明至少彭博有办法阻止这种自动访问。 有谁知道网站管理员可以实施什么来防止这种自动访问(就像彭博社实施的那样)。

虽然我同意互联网上的访问应该是免费的,但有时需要设置一些界限以防止未经授权的访问。

【问题讨论】:

标签: php html


【解决方案1】:

可以使用 .htaccess 文件中的以下内容轻松捕获 Wget。

RewriteCond %{HTTP_USER_AGENT} wget.* [NC]
RewriteRule .* - [F,L]

但是,如果用户代理字符串发生了变化,那么你可能永远不会知道它是 Wget。

您还可以查看如何阻止机器人。 http://www.robotstxt.org/

http://www.javascriptkit.com/howto/htaccess13.shtml

【讨论】:

  • 感谢@AndreiLupuleasa 的投入。使用 htaccess 很棘手,而且我对 htaccess 不是很熟悉,所以如果您能详细说明上述代码的实际作用,将会有所帮助?
  • 你可以看看这个教程javascriptkit.com/howto/htaccess13.shtml,他们解释了一切。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-15
  • 2013-09-18
  • 2015-06-26
  • 1970-01-01
  • 1970-01-01
  • 2013-12-30
  • 2021-04-12
相关资源
最近更新 更多