javascript - 为什么 Googlebot 从纯 JSON 网址请求 HTML?

标签 javascript ruby-on-rails bots google-search googlebot

在这样的页面上:https://medstro.com/groups/nejm-group-open-forum/discussions/61

我有这样的代码:

$.getJSON("/newsfeeds/61?order=activity&type=discussion", function(response) {
  $(".discussion-post-stream").replaceWith($(response.newsfeed_html));
  $(".stream-posts").before($("<div class=\'newsfeed-sorting-panel generic-12\' data-id=\'61\'>\n<div class=\'newsfeed-type-menu generic-12\'>\n<ul class=\'newsfeed-sorting-buttons\'>\n<li>\n<span>\nShow\n<\/span>\n<\/li>\n<li>\n<select id=\"type\" name=\"type\"><option selected=\"selected\" value=\"discussion\">Show All (15)<\/option>\n<option value=\"discussion_answered\">Answered Questions (15)<\/option>\n<option value=\"discussion_unanswered\">Unanswered Questions (0)<\/option><\/select>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n"));
  Newsfeed.prepare_for_newsfeed_sort($(".newsfeed-sorting-panel"));
});

Googlebot 已决定要查看 /newsfeeds/61?order=activity&type=discussion 是否有任何有趣的 HTML。因此,它会尝试抓取请求 HTML 的 URL,而我的应用会报告错误。 “ActionView::MissingTemplate:缺少模板新闻源/显示...”

  1. 为什么 Googlebot 会尝试抓取此网址?仅仅因为它认为那里有可能有一些有趣的东西并且它试图抓取所有东西?还是因为我的代码有问题?
  2. 在 Rails 中处理这个问题的最佳方法是什么?我不想忽略所有 MissingTemplate 错误,因为可能会有一些情况表明确实存在错误。忽略机器人创建的错误也是如此。我还有其他选择吗?

最佳答案

大概它从页面源解析了该 URL,并且只是试图抓取您的网站。

最好使用网站的 sitemap.xml 文件和 robots.txt 文件告诉 Google 抓取/不抓取哪些内容。

您可以告诉 Googlebot 不要使用 robots.txt 中的这些(或任何)GET 参数抓取页面:

Disallow: /*?

关于javascript - 为什么 Googlebot 从纯 JSON 网址请求 HTML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27750397/

相关文章:

ruby-on-rails - 如何使用 whenever gem 创建用于暂存和生产的相同 cron 作业?

ruby-on-rails - Rails 数据库唯一性验证不起作用

mysql - Rails mysql 错误问题 - 可能表未链接

java - IntelliJ event.getmessage() 和 "event"已识别

javascript - 宽度 : 100% is not working on children div if parent div has width: calc(100% - 300px)?

javascript - Jquery 模态保留以前的值

javascript - Javascript 可以帮我按 Enter 键吗?

python - Discord py bot 限制玩家对投票的一个 react

javascript - 在 Javascript 中控制 ASP.Net TreeView

javascript - 可调整大小的文本区域不断调整大小 onkeyup 而不是等待内容溢出