我正在嘗試編寫一個腳本,它允許我登錄到在zencart上運行的網站的密碼保護區域並以字符串形式抓取html。到目前爲止,它將下載HTML頁面作爲.html文件,但僅下載頁面的公共版本(即未成功登錄)。這是HTTPS,我相信這可能是它不工作的原因的一部分。有什麼不對我的腳本是什麼捲曲的設置,我需要(有上的捲曲的PHP很少文檔可悲的是:()CURL登錄和檢索頁面
<?php
$username = "[email protected]";
$password = "xxxxx";
$securityToken = "b6afe5babdd1b6be234d1976586fb1f1";
$loginUrl = "https://www.xxxxxxx.com.au/index.php?main_page=login&action=process";
//init curl
$ch = curl_init();
//Set the URL to work with
curl_setopt($ch, CURLOPT_URL, $loginUrl);
// ENABLE HTTP POST
curl_setopt($ch, CURLOPT_POST, 1);
//Set the post parameters
curl_setopt($ch, CURLOPT_POSTFIELDS, 'email_address='.$username.'&password='.$password.'&securityToken='.$securityToken);
//Handle cookies for the login
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie122.txt');
//Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL
//not to print out the results of its query.
//Instead, it will return the results as a string return value
//from curl_exec() instead of the usual true/false.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//execute the request (the login)
$store = curl_exec($ch);
//the login is now done and you can continue to get the
//protected content.
//set the URL to the protected file
curl_setopt($ch, CURLOPT_URL, 'http://www.xxxxxxx.com.au/index.php?main_page=product_info&products_id=1488');
//execute the request
$content = curl_exec($ch);
//save the data to disk
file_put_contents('test122.html', $content);
if(curl_error($ch)) {
$error = curl_error($ch);
echo $error;
}
?>
感謝,但沒有運氣 – Melbourne2991