简体   繁体   English

Facebook爬网时执行Javascript

[英]Execute Javascript when Facebook crawls website

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 ? 我使用下面的javascript函数将嵌入的Facebook元数据移动到头部,这对访问者而言效果很好,但在FB抓取页面时不起作用,当Facebook抓取页面时如何执行此操作?

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();

I need to get the meta data in head when facebook crawls the page 当Facebook抓取页面时,我需要获取元数据

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

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

How can i execute this when Facebook crawling the page ? Facebook抓取页面时如何执行此操作?

Not at all , of course. 当然不会

Facebook's scraper just looks at the HTML code of your page; Facebook的刮板只是查看您页面的HTML代码; it's not a full-fledged “browser” that would execute any client site code. 它不是可以执行任何客户端站点代码的成熟“浏览器”。

You'll have to put your OG meta data into the HTML code that get's delivered when the URL is requested. 您必须将OG元数据放入请求URL时提供的HTML代码中。 That's how it works. 就是这样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM