我試圖做一個腳本,登錄到我的Linkbucks帳戶來獲取我當前的統計信息。cURL登錄到Linkbucks
他們提供和API,但僅用於創建鏈接,我需要的是你得到的統計數據。
東西,我發現:
- 首先,你必須保持登錄
- 爲了得到統計,該網站做一個Ajax調用:用JSON後這樣https://www.linkbucks.com/Profile.aspx?task=manageLinks&action=loadPublisherStats:{「月」: 「09/01/2015」}。
這篇文章很容易得到我需要的信息,問題是我的腳本不工作。
我與你分享代碼,所以請幫助我。
任何想法或解決方案,或任何將被讚賞。
這裏是我的腳本:
<?php
$urlLogin = "https://www.linkbucks.com/Default.aspx";
$ch = getSource($urlLogin);
$fuente = curl_exec($ch);
$re = "/<input type=\"hidden\" name=\"__VIEWSTATE\" id=\"__VIEWSTATE\" value=\"(.*?)\" \\/>/";
preg_match($re, $fuente, $matches);
$re = "/<input type=\"hidden\" name=\"__EVENTVALIDATION\" id=\"__EVENTVALIDATION\" value=\"(.*?)\" \\/>/";
preg_match($re, $fuente, $validation);
$re = "/<input type=\"hidden\" name=\"__VIEWSTATEGENERATOR\" id=\"__VIEWSTATEGENERATOR\" value=\"(.*?)\" \\/>/";
preg_match($re, $fuente, $generator);
$post = array(
"ctl00\$ctl00\$phMenu\$LeftMenuBar\$ctl00\$Username" => "yourusername" ,
"ctl00\$ctl00\$phMenu\$LeftMenuBar\$ctl00\$Password" => "yourpassword" ,
"__VIEWSTATE" => $matches[1] ,
"__VIEWSTATEGENERATOR" => $generator[1] ,
"__EVENTVALIDATION" => $validation[1]
);
$data = postData($urlLogin, $post);
echo $data;
function getSource($url, $header = null) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$config['useragent'] = 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.33 (KHTML, like Gecko) Ubuntu/9.10 Chromium/13.0.752.0 Chrome/13.0.752.0 Safari/534.33';
curl_setopt($ch, CURLOPT_USERAGENT, $config['useragent']);
curl_setopt($ch, CURLOPT_REFERER, (is_null($header) ? 'https://www.google.com/' : $header));
return $ch;
}
function postData($url , $array) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_REFERER, "https://www.linkbucks.com/Default.aspx");
$server_output = curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, 'https://www.linkbucks.com/Default.aspx?ReturnUrl=%2fManageLinks');
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$server_output = curl_exec($ch);
return ($server_output);
}
?>
你得到什麼錯誤? – enkrates
我沒有得到任何錯誤,只是代碼不工作,但現在解決了! – Alberto