在这样的页面上: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:缺少模板新闻源/显示...”
- 为什么 Googlebot 会尝试抓取此网址?仅仅因为它认为那里有可能有一些有趣的东西并且它试图抓取所有东西?还是因为我的代码有问题?
- 在 Rails 中处理这个问题的最佳方法是什么?我不想忽略所有 MissingTemplate 错误,因为可能会有一些情况表明确实存在错误。忽略机器人创建的错误也是如此。我还有其他选择吗?
最佳答案
大概它从页面源解析了该 URL,并且只是试图抓取您的网站。
最好使用网站的 sitemap.xml 文件和 robots.txt 文件告诉 Google 抓取/不抓取哪些内容。
您可以告诉 Googlebot 不要使用 robots.txt 中的这些(或任何)GET 参数抓取页面:
Disallow: /*?
关于javascript - 为什么 Googlebot 从纯 JSON 网址请求 HTML?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27750397/