Why is php domdocument getelementsbytagname not finding all elements?

Status
Not open for further replies.

filenuke

Active Member
118
2013
28
0
Im trying to make php script to get all links for a movie from movie2k and tell me the movie quality of each link.

PHP Code:
PHP:
<?php 
$html = file_get_contents('http://www.movie2k.tv/Drinking-Buddies-watch-movie-16747914.html');
$scrapedmovie = new DOMDocument();
$scrapedmovie->loadHTML($html);
$movieslinks = $scrapedmovie->getElementById('menu')->getElementsByTagName('tr');//get all rows in table with links
$totalLinks = $movieslinks->length - 1;//how many links we found.  we minus 1 because first row is useless
//loop and put the quality of movie and link in arrays
//we skip the 1st row coz its not having anything useful in it (i=1 instead of 0)
for ($i = 1; $i<$totalLinks + 1; $i++)
{
        $movielink[$i - 1] = $movieslinks->item($i)->getElementsbyTagName('a')->item(0)->getAttribute('href');
          $moviequality[$i - 1] =    $movieslinks->item($i)->getElementsbyTagName('td')->item(1)->getElementsByTagName('img')->item(0)->getAttribute('title');
          $moviequality[$i - 1] = substr($moviequality[$i - 1], 14,   strlen($moviequality[$i - 1]) - 14);//get rid of useless part of   moviequality string
}
echo "<b>Total " . $totalLinks . ' hoster links found.</b><br>';
print_r($movielink);
echo "<br>";
print_r($moviequality);?>


for some reason i cant get the domdocument getelementsbyname to find all the rows in the table with the links, it finds some of them but not all the links.
In the picture and in the html of the url it downloads u can see that there are 12 links and 13 table rows.

55r6tjph.png

When i try to run it it only returns 8 links and not 12, returning
PHP:
<b>Total 8 hoster links found.</b><br>Array
(
    [0] => Drinking-Buddies-watch-movie-16747911.html
    [1] => Drinking-Buddies-watch-movie-16747913.html
    [2] => Drinking-Buddies-watch-movie-16747910.html
    [3] => Drinking-Buddies-watch-movie-16747903.html
    [4] => Drinking-Buddies-watch-movie-16747909.html
    [5] => Drinking-Buddies-watch-movie-16747902.html
    [6] => Drinking-Buddies-watch-movie-16747914.html
    [7] => Drinking-Buddies-watch-movie-16747905.html
)
<br>Array
(
    [0] => DVDRip/BDRip 
    [1] => DVDRip/BDRip 
    [2] => DVDRip/BDRip 
    [3] => DVDRip/BDRip 
    [4] => DVDRip/BDRip 
    [5] => DVDRip/BDRip 
    [6] => DVDRip/BDRip 
    [7] => DVDRip/BDRip 
)
Can anyone tell my why it wont find 12 links like its supposed to and why getelementsbytagname wont return 13 rows? I dont know what im doing wrong :(
 
5 comments
I tried:
Code:
$count = 0;
$trs = $scrapedmovie->getElementsByTagName('tr');
foreach ($trs as $tr){
	if ($tr->getAttribute('id')=="tablemoviesindex2"){
		echo $tr->getElementsByTagName('a')->item(0)->getAttribute('href') . PHP_EOL;
		$count++;
	}
}
echo 'There are ' . $count . ' matching links.';
But only got 9 links.

I'll try again but I usually don't use php for scraping web pages.
 
Thanks a LOT
I never really thought this would be the case as it could find some links, luckily its easy to pull the links from the JS
 
Status
Not open for further replies.
Back
Top