gpt4 book ai didi

ruby-on-rails - angularjs:使用 Ruby On Rails 的 ajax 网站无法抓取

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:35:01 24 4
gpt4 key购买 nike

<分区>

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

例如:

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

我在 rails 中实现了 Index 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

我使用的 Controller :-

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

爬虫 Controller

    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 相关人员建议我在 url 中不使用 hashbang(推送状态)来实现网站。这是解决问题的正确方法吗?

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

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

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com