【问题标题】:angularjs: ajax website using Ruby On Rails not crawling [closed]angularjs:使用 Ruby On Rails 的 ajax 网站不爬行 [关闭]
【发布时间】:2014-01-29 07:17:38
【问题描述】:

我正在尝试使 angularjs 网站可爬行。为此,我正在使用 Google 建议的 ?_escaped_fragment= 解决方案。

例如:

当 google 看到带有像 "http://xample.com/#!/Home" 这样的哈希片段的请求时,它会将 url 转换为 "http://xample.com/?_escaped_fragement_=/Home"

我在 rails 中实现了Index controller,它接受此类请求并将该请求重定向到crawler controller,而crawler controller 又向Google 提供动态生成的HTML 快照。

但是除了我的主页http://xample.com/ 没有其他页面被抓取。(可能是因为 hashbang)

以下是谷歌建议的实施 ?_escaped_fragment_= 解决方案后仍未抓取的网址:-

http://xample.com/#!/Home
http://xample.com/#!/xyz
http://xample.com/#!/abc
http://xample.com/#!/def

我使用的控制器:-

Index controller 接受带有 "?_escaped_fragment_="

的 Url
    class IndexController < ApplicationController
      def index()
        if params['_escaped_fragment_'] == '/Home'
          redirect_to :controller=>'crawler', :action => 'crawlhome'
          return
        elsif params['_escaped_fragment_'] == '/Xyz'
         redirect_to :controller=>'crawler', :action => 'crawlxyz'
          return
        end
 elsif params['_escaped_fragment_'] == '/abc'
         redirect_to :controller=>'crawler', :action => 'crawlabc'
          return
        end
    end

 elsif params['_escaped_fragment_'] == '/def'
         redirect_to :controller=>'crawler', :action => 'crawldef'
          return
        end
end

爬虫控制器

    class CrawlerController < ApplicationController
      layout false
      require 'net/http'
      require 'uri'
      def crawlhome
      @data = "getting data from api and displaying same data in view"
      end

      def crawlXyz
      @data = "getting data from api and displaying same data in view"
      end

       def crawlabc
      @data = "getting data from api and displaying same data in view"
      end

   def crawldef
      @data = "getting data from api and displaying same data in view"
      end
    end

在我公司工作的 Seo 相关人员建议我实施网址中没有hashbang(推送状态)的网站。这是解决问题的正确方法吗?

这在非 Html 浏览器中不起作用。

实现http://xample.com/#!/Home可能有什么问题。为什么在上述情况下它不爬网。

我在论坛上尝试了许多不同的解决方案,但仍然没有给我正确的结果。

【问题讨论】:

    标签: ruby-on-rails ajax angularjs seo bots


    【解决方案1】:

    实际上上面的代码是有效的。谷歌在 4 天(长时间)后开始抓取..认为代码有错误。

    希望这对其他开发者有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-29
      • 2010-09-15
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      相关资源
      最近更新 更多