如何在 Django 中处理网络爬虫?

发布于 2024-10-08 06:19:14 字数 111 浏览 0 评论 0原文

由于网络爬虫在没有任何请求数据的情况下访问了我网站的某些部分,我的电子邮件中收到了很多错误,我想知道在 Django 中处理网络爬虫的最佳方法是什么?当我遇到空的 QueryDict 时,我应该发出重定向吗?

I've been getting a lot of errors sent to my e-mail due to web crawlers hitting parts of my site without any request data, and I was wondering what is the best way to handle web crawlers in Django? Should I issue a redirect when I come across an empty QueryDict?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

对风讲故事 2024-10-15 06:19:14

您可以考虑实施 robots.txt 来禁止抓取工具访问您网站上的目标区域仅限于人类,例如形式。

You could consider implementing a robots.txt to disallow crawlers from accessing areas of your site that are intended for humans only, such as forms.

神经大条 2024-10-15 06:19:14

我认为您的视图应该适用于任何请求,在列表返回页面上显示消息“错误的请求”。 500 太丑了您确定用户不会在没有任何请求数据的情况下打开页面吗? QueryDict 的“get”方法可以帮助设置默认值。

I think your views should work with any request, at list return page with message "Incorrect request". 500 is ugly. Are you sure that user don't open page without any request data? "get" method of QueryDict can help with default values.

北恋 2024-10-15 06:19:14

行为良好的爬虫应该只执行 GET 请求。表单不应该是 GET 请求。

Ruby 和 Rails 使用 CRUD 映射

Create -> POST,
READ -> GET, 
Update -> PUT, 
Delete -> DELETE

只有没有附加信息的东西才应该是 GET 请求。

Well behaved crawlers should only do GET requests. Forms should be anything but GET requests.

Ruby and Rails uses CRUD mapping

Create -> POST,
READ -> GET, 
Update -> PUT, 
Delete -> DELETE

Only things without additional info should be GET requests.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文