I am a beginner in PHP and am working on a script that can extract Title / Description/ Tags (or keywords) from a Youtube webpage. For example, take any youtube page like http://www.youtube.com/watch?v=yADOdeZTD9c .. it’s HTML code contains
<meta name="keywords" content="nirvana, unplugged, performing, tocando, cantando, come, as, you, are, Come, As, You, Are, nevermind, live, en, vivo, 1992, 1993, acoustic, acustica, complet...">
My code is able to extract keywords from the above line. Relevant part of the code is given below:
$meta_elements = $pageDOM->getElementsByTagName('meta');
foreach ($meta_elements as $meta_element) {
if (strtolower($meta_element->getAttribute('name')) == 'description')
{
$aValues['description'] = $meta_element->getAttribute('content');
echo $meta_element->getAttribute('content');
}
}
I was trying to modify it to extract the Category information but I’m unable to do so since the Category name can not be extracted in way same as Keywords or Description.
I think the part within HTML code of website, from where I can extract the category is this:
Category:
</h4>
<p id="eow-category"><a href="/music">Music</a></p>
Any suggestions regarding how to extract “Music” (case doesn’t matter) are very much appreciated..
Thank you 🙂
Why in the world would you scrape pages from YouTube.com when the information you need is available through YouTube Data API. You can get the category information and just about anything in less than one minute. You don’t even need PHP. Just run this example code in console:
PHP code is much simpler. You just need 2-3 lines of code.
Having said that, what does this give you?