<?php
function curl($url) {
$options = Array(
CURLOPT_RETURNTRANSFER => TRUE, // Setting cURL's option to return the webpage data
CURLOPT_FOLLOWLOCATION => TRUE, // Setting cURL to follow 'location' HTTP headers
CURLOPT_AUTOREFERER => TRUE, // Automatically set the referer where following 'location' HTTP headers
CURLOPT_CONNECTTIMEOUT => 120, // Setting the amount of time (in seconds) before the request times out
CURLOPT_TIMEOUT => 120, // Setting the maximum amount of time for cURL to execute queries
CURLOPT_MAXREDIRS => 10, // Setting the maximum number of redirections to follow
CURLOPT_USERAGENT => "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1a2pre) Gecko/2008073000 Shredder/3.0a2pre ThunderBrowse/3.2.1.8", // Setting the useragent
CURLOPT_URL => $url, // Setting cURL's URL option with the $url variable passed into the function
);
$ch = curl_init(); // Initialising cURL
curl_setopt_array($ch, $options); // Setting cURL's options using the previously assigned array data in $options
$data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
curl_close($ch); // Closing cURL
return $data; // Returning the data from the function
}
function regex_scrape($regex,$results_page){
preg_match_all($regex,$results_page,$match);
return $match;
}
$continue = TRUE;
$prices = array();
$url = "https://www.airbnb.de/s/Prague~Prague-1--Czech-Republic";
while ($continue == TRUE) {
$results_page = curl($url); // Downloading the results page using our curl() funtion
$prices2 = regex_scrape('/<span class=\"h3 price-amount\">(.*)span>/',$results_page);
//PRINTING ARRAY SUM NOT WORKIN
var_dump($prices2[0]);
echo 'TOTAL: ' . array_sum(array_values($prices2[0]));
$prices = array_merge($prices,$prices2[0]);
if (strpos($results_page, "<li class=\"next next_page\">")) {
$continue = FALSE;
preg_match('/<li class="next next_page"><a target=".*" rel="next" href="(.*)"><i class="icon icon-caret-right">/',$results_page,$url);
$url = 'https://www.airbnb.de' . $url[1];
} else {
$continue = FALSE; // Setting $continue to FALSE if there's no 'Next' link
}
sleep(rand(0,1)); // Sleep for 3 to 5 seconds. Useful if not using proxies. We don't want to get into trouble.
}
?>