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

PHP Curl显示的页面与浏览器中的页面不同,php,curl,Php,Curl,我试图在通过curl登录网站后从网站上抓取账单列表,但其中一个页面上的内容与我的浏览器中的内容不同(即,不是显示账单列表,而是显示“无法显示您的账单历史记录”)。我可以正确地刮取其他只有在登录后才可用的页面,所以我对为什么在我使用curl时该页面拒绝显示账单历史感到非常困惑 这是我的密码: //Load login page $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://www.domain.com/login'); curl

我试图在通过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
//加载登录页面
$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(windowsnt 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\u exec($ch);
//将帖子提交到登录页面以进行身份验证
$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\u exec($ch);
//现在我们已登录,请转到我的帐户主页
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\u exec($ch)//显示与浏览器中相同的内容

$accountNumber=return\u介于($webpage,'id=“accountID1”>,'之间您可以添加“真实”浏览器通常传输的其他标题字段:

$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,那么就可以使用方便的“实时HTTP头”在加载相关页面时,请插入并检查浏览器传输的标题。然后尝试执行相同操作。

他们可能有htaccess规则阻止编写脚本……我如何绕过这些规则?我假设有可能让他们相信我是浏览器访问者。如果他们有阻止爬行、刮取或其他任何伪造用户代理的东西(这都是一个假设,我不知道他们设置了什么,或者他们是谁)我在一些网站上工作过,这些网站需要通过计算交互周期进行人机交互,就像我说的,不知道他们设置了什么,这些只是潜在的。你说的交互周期是什么意思?谢谢-我补充了这一点(基于所示的篡改数据标头请求),它仍然显示相同的错误消息。