本文介绍了如何做到像AngularJS,小胡子,把手客户端模板引擎的Facebook的Open Graph友好的meta标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我的测试,Facebook的爬虫不会使客户端模板,就像一个浏览器。

我想避免一个网络服务器和建筑物的HTML文件的Open Graph不惜一切代价对象。我想生成通过URL飞meta标签,但似乎Facebook的不能做到这一点。

可以从Facebook有人请证实?我问的Open Graph的头在#mobiledevcon她说Facebook能够呈现的东西,如{{值}}

我的meta标签如下所示,它们在每个浏览器渲染罚款。但Facebook的Open Graph的调试器只能看到原始文本,而不是插值内容。

 <财产元={{meta.property}}CONTENT ={{meta.content}}>


解决方案

当你仔细想想应该很清楚,为什么这是行不通的。

的实履带,因为它是由服务器提供下载的HTML。 Facebook的履带式的不会执行任何JavaScript,像所有的爬虫不会执行JavaScript。这是由于安全限制和速度的原因(他们没有足够的时间在他们的服务器上执行JavaScript。)

没办法解决这个问题。如果你想爬虫索引你页面,你需要给他们你希望他们能够直接读取的。

提示::您可以使用类似呈现在服务器端页面和服务于这个到爬虫。

According to my testing, Facebook's crawlers do not render client-side templates like a browser.

I want to avoid a webserver and building HTML files for Open Graph objects at all costs. I want to generate the meta tags on the fly via the URL, but it seems Facebook cannot do this.

Can someone from Facebook please confirm? I asked the head of Open Graph at #mobiledevcon and she said that Facebook can render stuff like {{value}}

My meta tags are as follows, and they render fine in every browser. But the Facebook Open Graph Debugger only sees the raw text, not the interpolated content.

<meta property="{{meta.property}}" content="{{meta.content}}">
解决方案

When you think about it it should be clear, why this does not work.

The Facebook crawler downloads the HTML as it is served by the server. The Facebook crawler will not execute any JavaScript, like all the crawler will not execute the JavaScript. This is due to security restrictions and for speed reason (they do not have the time execute JavaScript on their servers.)

There is no way around this. If you want the crawler to index you page, you need to give them directly what you want them to read.

Tip: You could use something like phantom.js to render your pages on the server side and serve this to the crawlers.

这篇关于如何做到像AngularJS,小胡子,把手客户端模板引擎的Facebook的Open Graph友好的meta标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 13:34