Click here to Skip to main content
15,886,761 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello !

I have this piece of code :

PHP
require_once("Xpath.php");
    //ini_set('xdebug.max_nesting_level', 200);
    scrape("http://filmehd.net/page/1");

    set_time_limit(0);
    function scrape ($url)
    {
    $xpath = new XPATH($url);

    $get_image_src = $xpath->query('//h2/a/img/@src');
    $get_image_movie_src =  $xpath->query('//h2[2]/a/@href');
    $get_image_movie_anchor = $xpath->query('//h2/a/@title');
    $next_page = $xpath->query('//div/a[10]/@href');
    $data = array();
    echo"<pre>";
    for($x =0 ; $x<$get_image_movie_anchor->length; $x++)
    {
        // $data[$x]['image_src'] = $get_image_src->item($x)->nodeValue;
         $data[$x]['image_movie_src'] = $get_image_movie_src->item($x)->nodeValue;
        // $data[$x]['image_movie_anchor'] = $get_image_movie_anchor->item($x)->nodeValue;
        echo $data[$x]['image_movie_src'] ;
        //echo '<div><a href="'.$data[$x]['image_movie_src'].'"><img src="'.$data[$x]['image_src'].'"/>'.$data[$x]['image_movie_anchor'].'</a></div>';
    }

    if($next_page->length > 0)
    {
        scrape($next_page->item(0)->nodeValue);
    }
    }


when i run the page using this code i get :
Quote:
Notice: Trying to get property of non-object in C:\wamp\www\scraper\filmeHdScraper.php on line 20


if i modify :

Quote:
//h2[2]/a/@href

to
Quote:
//h2/a/@href

the error goes away ,the problem is that if i use the xpath that doesn't generate the error i will get duplicate content because on that website there are two h2 tags . What do i do ? how can i make
Quote:
//h2[2]/a/@href
work ?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900