Facebook爬网时执行Javascript [英] Execute Javascript when Facebook crawls website

查看:56
本文介绍了Facebook爬网时执行Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的javascript函数将嵌入的Facebook元数据移动到头部,这对于访问者而言工作正常,但在FB抓取页面时不起作用,当Facebook抓取页面时如何执行此操作?

I use javascript function below to move embed Facebook Meta data to head, This works fine for visitors but not when FB crawls the page, How can i execute this when Facebook crawling the page ?

function metaBodyToHead() {

    var head = document.head,
        metaTAGs = document.getElementsByTagName( "DIV" );

    for( var i = 0, ln = metaTAGs.length; i < ln; i++ ) {

        head.appendChild( metaTAGs[ i ].parentNode.removeChild( metaTAGs[ i ] ) );
    }
}

metaBodyToHead();

在Facebook抓取页面时,我需要先获取元数据

I need to get the meta data in head when facebook crawls the page

测试页: http://greenboxmedia.org/meta.html

Facebook调试: https://developers.facebook.com/tools/debug/og/object?q=www.greenboxmedia.org%2Fmeta.html

Facebook debug: https://developers.facebook.com/tools/debug/og/object?q=www.greenboxmedia.org%2Fmeta.html

推荐答案

Facebook爬行页面时如何执行此操作?

How can i execute this when Facebook crawling the page ?

一点也不.

Facebook的抓取工具仅查看您页面的HTML代码;它不是可以执行任何客户端站点代码的成熟的浏览器".

Facebook’s scraper just looks at the HTML code of your page; it’s not a full-fledged "browser" that would execute any client site code.

您必须将OG元数据放入请求URL时提供的HTML代码中.就是这样.

You’ll have to put your OG meta data into the HTML code that get’s delivered when the URL is requested. That’s how it works.

这篇关于Facebook爬网时执行Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆