0
我想从私人论坛中提取一些数据。我创建了一个使用CURL登录的PHP脚本,并使用DOMDocument来提取页面数据。PHP Curl登录论坛,但不会保持登录状态?
我已成功使用脚本登录,但它的行为就像我尝试使用loadHTMLFile()加载网页时从未登录一样。
有人告诉我可能需要发送cookie标头吗?但我不知道该怎么做,或者甚至有必要。
任何人有任何想法?
<?
function vBulletinLogin($user, $pass)
{
$md5Pass = md5($pass);
$data = "do=login&url=index.php&vb_login_md5password=$md5Pass&vb_login_username=$user&cookieuser=1";
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "****"); // replace ** with tt
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt ($ch, CURLOPT_TIMEOUT, '10');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
curl_setopt($ch, CURLOPT_COOKIEJAR, "/public_html/phpcrawl/cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "/public_html/phpcrawl/cookies.txt");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERRER, "****");
$store = curl_exec ($ch);
echo $store; <- **this shows that I have successully logged in, it gives me a welcome message**
print_r($_COOKIE);
curl_close($ch);
$pos = strpos($store, "Thank you for logging in");
if($pos === FALSE) RETURN 0;
else RETURN 1;
}
if(vBulletinLogin("****","****")) echo "Logged In";
else echo "Failed to Login check User/Pass";
$url="http://texturl.com";
echo $url."<br>";
//get new HTML document
$html = new DOMDocument();
$html->loadHTMLFile($url);
print $html->saveHTML(); <- shows a login and password box saying I am not logged in.
非常感谢您的帮助。得到它的工作。 – 2010-11-23 04:37:50