Kan iemand mij helpen met de mogelijkheid om in onderstaande script Paging mogelijk te maken?

Ik run de pagina mbv simple html dom. en start op de pagina:
http://www.imdb.com/search/title?year=2016,2016&title_type=feature&sort=moviemeter,asc

De XPATH om naar de volgende pagina te gaan is:
//*[@id="main"]/div/div/div[4]/div/a


<?php
$current_year = date("Y");
//$current_year = "2015";
$movie_title = $row["title"];

//Start xpath scraping
$source = file_get_contents('http://www.imdb.com/search/title?year='.$current_year.','.$current_year.'&title_type=feature&sort=moviemeter,asc';);

$dom = new DOMDocument();

@$dom->loadHTML($source);

$xpath = new DOMXPath($dom);

$rows = $xpath->query("//*[@id=\"main\"]/div/div/div[3]/div/div[3]/h3/a");

foreach($rows as $index => $row){
//echo ($index + 1) . ') ' . $row->textContent . '<br />';
$title_results = $row->textContent;

//preg_replace('/[^A-Za-z0-9\-\']/', '', $title_results);
$title_results_clean = preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '', $title_results);
//echo $title_results_clean;




//Check if title exist
$query = mysqli_query($connection, "SELECT * FROM video WHERE title='".$title_results_clean."'");

if(mysqli_num_rows($query) > 0){

//echo "title already exists";
}else{
// insert the new item
mysqli_query($connection, "INSERT INTO video (`title`) VALUES ('".$title_results_clean."')");

}



}

?>

Reageren