问题
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