Reputation: 101
I am using the following code to get the html code of a page and extract the price later on for a price comparator :
<?php
function url_get_contents ($url) {
if (function_exists('curl_exec')){
$conn = curl_init($url);
curl_setopt($conn, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($conn, CURLOPT_FRESH_CONNECT, true);
curl_setopt($conn, CURLOPT_RETURNTRANSFER, 1);
$url_get_contents_data = (curl_exec($conn));
curl_close($conn);
}elseif(function_exists('file_get_contents')){
$url_get_contents_data = file_get_contents($url);
}elseif(function_exists('fopen') && function_exists('stream_get_contents')){
$handle = fopen ($url, "r");
$url_get_contents_data = stream_get_contents($handle);
}else{
$url_get_contents_data = false;
}
return $url_get_contents_data;
}
$html = url_get_contents("http://linktopage.com");
echo $html;
?>
However one of the website i want to get the price of an item from blocks this method and shows me 'your ip has been banned'. Is there an other way than file_gets_content (same result) and curl (code above) to get a html code from a page ?
If there is a better method to my problem that would be great too. Regards.
Upvotes: 1
Views: 659
Reputation: 353
If your IP banned, you should use proxy servers. "cURL" library can work with proxy, set CURLOPT_PROXY and other proxy-options in "curl_setopt" function.
Upvotes: 1