scraper not looping

Discussion in 'PHP' started by cavendano, Dec 1, 2008.

  1. #1
    I cant figure this out...
    is there a reason why this scraper would not loop?

    right now it retrieves one item and stops...

    rep will be given!!!

    <?php
    
    
    $page = (isset($_GET['page'])) ? $_GET['page'] : 0;
    $page = ($page < 1) ? 0 : $page;
    
    $srch = preg_replace( "/ /", "+", $_GET[search] );
    $url1 = "http://websitename.net/search/en.html?q=".$srch."&page=".$page;
    $res = file_get_contents($url1);
    
    $i = 1;
    $hitung = 0;
    $res = strstr($res,'<tr class="top">');
      if($res) {
        while($i <= 12) {
          	$res = strstr($res, '<td><h2>');
                	
    $dodol = extstr3($res,'<a href="/file/','</span>');
          	$theId = preg_match('/(.*)\/(.*)\//', $dodol, $results);
          $theId = preg_match('/(.*)\//', $results[1], $results);
    $theId = preg_match('/\/(.*)/', $results[1], $results);
          	//$dodol = strstr($dodol,$theId);
    $theId = $results[1];
    	$name = extstr3($dodol,'">','</a> <span>');
    		$res = strstr($res, '</table>');
    	
    	$name = trim($name);    
    	$name = str_replace('(','',$name);
    	$name = str_replace(')','',$name);
    	$name = str_replace('&#039;','',$name);
    	$name = str_replace('&','and',$name);
        	$name = str_replace("'",'',$name);
    
    
    	// Download URL
    	$download = "http://www.websitename.net/{$theId}/download.jpg";
    
    	// Play URL
    	$purl = $download;
    
    	$link = "src=websitename&id=".$theId."&name=".$name."&url=".$purl;
    	
            if ( $name && $link)
              {
                include( "the-template/list.inc.php" );
    	    $hitung++;
              }
            ++$i;
    
        }
    
    $nextpage = $p + 1;
    $prevpage = $p - 1;
    $nextpage = "?source=".$source."&search={$srch}&page={$nextpage}";
    $prevpage = "?source=".$source."&search={$srch}&page={$prevpage}";
    echo "<table width=\"100%\" align=\"center\"><tr>";
    if ( 1 < $p )
    {
        echo "<td align=\"left\"><a href=\"";
        echo $prevpage;
        echo "\">";
        echo $lang[Prev];
        echo "</a></td>";
    }
    if ( $hitung == 0 )
    {
        echo "<center>".$lang['NoResultsMSG']."</center>";
    }
    if ( $hitung != 12 )
    {
        echo "";
    }
    
    else
    {
        echo "<td align=\"right\"><a href=\"";
        echo $nextpage;
        echo "\">";
        echo $lang[Next];
        echo "</a></td>";
    }
        echo "</tr></table>";
      }  //end if($res)
    else {
        echo "<center>".$lang['NoResultsMSG']."</center>";
    }
    ?>
    
    
    PHP:
     
    cavendano, Dec 1, 2008 IP
  2. juust

    juust Peon

    Messages:
    214
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $nextpage = $p + 1;

    the $p variable should probably be $page ?
    now it seems to be used out of the blue
    so it always starts as $p=0
     
    juust, Dec 2, 2008 IP