PHP Curl显示的页面与浏览器不同

时间:2013-10-15 17:50:03

标签: php curl

我试图通过卷曲登录网站后从网站上删除账单清单,但在其中一个页面上的内容与我的浏览器中的内容不同(即,而不是显示它显示的账单清单“您的帐单历史记录无法显示“)。我可以正确地抓取登录后只能使用的其他页面,所以当我使用curl时,为什么该页面拒绝显示帐单历史记录时我很困惑。

这是我的代码:

//Load login page
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.domain.com/login');
curl_setopt($ch, CURLOPT_REFERER, 'https://www.domain.com');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:20.0) Gecko/20100101 Firefox/20.0');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieLocation);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieLocation);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$webpage = curl_exec($ch);

//Submit post to login page to authentify
$postVariables = 'emailAddress='.$username.
    '&password='.$password;
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postVariables);
curl_setopt($ch, CURLOPT_URL, 'https://www.domain.com/login/POST.servlet');
curl_setopt($ch, CURLOPT_REFERER, 'https://www.domain.com/login');
$webpage = curl_exec($ch);

//Go to my account main page now that we are logged in
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_URL, 'https://www.domain.com/My_Account');
curl_setopt($ch, CURLOPT_REFERER, $target);
$webpage = curl_exec($ch); //shows the same content as in the browser
$accountNumber = return_between($webpage, 'id="accountID1">', '<', EXCL); //this is correctly found

//Go to bills page
curl_setopt($ch, CURLOPT_URL, 'https://www.domain.com/Bill_History/?accountnumber='.$accountNumber);
curl_setopt($ch, CURLOPT_REFERER, 'https://www.domain.com/My_Account');
$webpage = curl_exec($ch); //Not showing the same content as in the browser

最后一个curl_exec是无效的。

我已经广泛检查了页面的逻辑并使用了防篡改数据来分析发生了什么:似乎没有任何javascript / ajax调用会单独拉出账单历史记录,而且没有POST请求:到目前为止正如我所见,账单历史记录应该在页面加载时显示。

关于我可以尝试解决什么或者可能是什么问题的任何想法?它在其他页面上工作的事实尤其令人费解。

提前致谢!

编辑:它仍然不起作用,但我在他们的网站上找到了另一个页面,我可以得到我需要的内容以及正确显示内容的地方 - 所以不再需要解决方案了。

1 个答案:

答案 0 :(得分:0)

您可以添加“真实”浏览器通常传输的其他标头字段:

$header[] = 'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
$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';

仅举几例。

如果您碰巧使用FFox,请获取方便的“Live HTTP Headers”插件,并检查浏览器在加载相关页面时传输的标头。然后尝试做同样的事情。

相关问题