Finding Open Graph tags on youtube

a 夏天 提交于 2019-12-23 14:59:05

问题


I'm working on a Tampermonkey script to hide related videos on youtube if the og:video:tag contains "League of Legends".

When I use the Open Graph Debugger (link) it find many tags (og:video:url, og:video:width, og:video:tag, ...) but when I search in the DOM I am unable to find any of these elements.

I've tried disabling all my extensions, from a clean profile, from incognito as well as using an Open Graph Extension still I can't find the tags.

Some other attempts:

$('[property="og:type"]') => null.

document.getElementsByTagName('meta') => two unrelated tags.

回答1:


YouTube video source contains those tags only if the userAgent is

facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)

or (I used this in my test)

facebookexternalhit/1.1

You can test these by adding a new device to DevTools with those user agents. I am not sure you want to use these tags, but you have two options:

  • If there is backend processer for finding these tags, you can switch the user agent to appropriate one there.
  • If you're working on a browser extension, you should set up a proxy that does the above for you. Send the video permalink and return an object of tags.


来源:https://stackoverflow.com/questions/46616703/finding-open-graph-tags-on-youtube

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!