0

Hello I'm making a php script to extract videos URL from Youtube result. I have this:

<?php
    error_reporting(1);

    function conseguir_codigo_url($url) {
        $dwnld = curl_init();
        curl_setopt($dwnld, CURLOPT_URL, $url);
        curl_setopt($dwnld, CURLOPT_HEADER, 0);
        //$userAgent = 'Mozilla/4.0 (compatible; MSIE 6.01; Windows NT 6.0)';
        curl_setopt($dwnld, CURLOPT_USERAGENT, $userAgent);
        curl_setopt($dwnld, CURLOPT_RETURNTRANSFER, true);

        $fuente_url = curl_exec($dwnld);
        curl_close($dwnld);
        return $fuente_url;
    }

    function extraer_atributo_elemento($fuente) {
        $file = new DOMDocument;

        if($file->loadHTML($fuente) and $file->validate()){

            echo "DOCUMENTO";

            $file->getElementById("search-results");

        }

     $codigo_url = conseguir_codigo_url("http://www.youtube.com/results?search_sort=video_date_uploaded&uni=3&search_type=videos&search_query=humor");
    extraer_atributo_elemento($codigo_url);
?>

The trouble is I can't use getelementbyid, I think it's maybe html5. Have you a suggestions to solve this. I need parse the source and I don't know regex . So domdocument is the only way.

3
  • at first you should consider using SimpleXML php.net/manual/de/book.simplexml.php Commented Jan 13, 2013 at 15:38
  • 1
    This is unlikely to get you anywhere. YouTube go through great lengths to make their content un-downloadable. Either way, you should provide a more specific problem description. What exactly goes wrong? Commented Jan 13, 2013 at 15:38
  • secondly you should REALLY use english methods. this would probably help understanding the code much faster! Commented Jan 13, 2013 at 15:44

1 Answer 1

1

Why do you use $file->validate()? If you just want to extract an element by ID, no need to call this. Also, setting DOMDocument::recover to true before calling loadHTML may help to parse broken HTML from the net.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.