Reputation: 45
this is my php code
<?php
$agents = array(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:7.0.1) Gecko/20100101 Firefox/7.0.1',
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100508 SeaMonkey/2.0.4',
'Mozilla/5.0 (Windows; U; MSIE 7.0; Windows NT 6.0; en-US)',
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_7; da-dk) AppleWebKit/533.21.1 (KHTML, like Gecko) Version/5.0.5 Safari/533.21.1');$header[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$header[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-us,en;q=0.5";
$header[] = "Pragma: ";//assign to the curl request.
$url = 'http://ball-control.com';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl,CURLOPT_USERAGENT,$agents[array_rand($agents)]); //random agent
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);//set header
$result = curl_exec($curl);
curl_close($curl);
print htmlspecialchars($result);
?>
this website (ball-control.com) blocked curl function. but i need it.
and this is result
<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head><body><form method="POST" id="super">
<script>document.getElementById('super').style.display="none";</script>
<input type="hidden" value="1" name="wlsec"><center>
<br>Чтобы продолжить работу с сайтом, пожалуйста, нажмите кнопку «Продолжить».<br><br>
<input value="Продолжить" type="submit"></center>
</form><script>document.getElementById('super').submit()</script>
</body></html>
and this result is wrong, I need to real content of this website. how can I scrape or fetch content of this website? PLZ help. tnx
Upvotes: 0
Views: 91
Reputation: 47159
There are several things missing from your cURL
request, mostly related to not having set CURLOPT_POSTFIELDS
, CURLOPT_REFERER
, CURLOPT_COOKIEFILE
.
There's a hidden form on the page that requires wlsec
be submitted with a value of 1
. After that the site checks to see what the referer is, and finally verifies the cookie and php session id.
$formdata = array('wlsec' => '1');
$url = 'http://ball-control.com';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_REFERER, $url);
curl_setopt($curl, CURLOPT_COOKIEFILE, '/tmp/cookies.txt'); // set cookie file
curl_setopt($curl, CURLOPT_COOKIEJAR, '/tmp/cookies.txt'); // same file as above
Adding the following to your script in addition to what you already have should resolve the issues.
Upvotes: 1
Reputation: 361
Just analyzing this result you had posted, they are trying to avoid bots with a hidden form
<?php
$url = "http://ball-control.com/";
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER=>true,
CURLOPT_URL=>$url,
CURLOPT_FOLLOWLOCATION=>true,
CURLOPT_TIMEOUT=>10,
CURLOPT_CONNECTTIMEOUT=>60,
CURLOPT_COOKIEFILE=>"",
CURLOPT_POST=>true,
CURLOPT_POSTFIELDS=>["wlsec"=>"1"]]);
$result = curl_exec($ch);
curl_close($ch);
print htmlspecialchars($result);
?>
You can see that the hidden post fields are wlsec and must return 1
Upvotes: 1