0
我正在尝试使用cURL来自动执行涉及多个步骤的登录。我遇到的问题是我登录的第一页正常,但下一页我打了我必须选择或点击链接才能继续。我怎么“继续前进”。我试着拿下一个URL并将其放入我的cURL代码中,但它不起作用,因为它直接进入该页面和错误,因为我没有进入登录过程的第一页。这是我的代码。cURL遍历多个页面的登录
$ch = curl_init();
$data = array('fp_software' => '', 'fp_screen' => '', 'fp_browser' => '','txtUsername' => "$username", 'btnLogin' => 'Log In');
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_URL, 'https://www.website.com/Login.aspx');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_exec($ch);
curl_close ($ch);
下一个URL是www.website.com/PassMarkFrame.aspx - 基本上,我需要抓取抛出此登录过程。
我试过这个......但它没有工作。
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_URL, 'https://www.website.com/Login.aspx'); // use the URL that shows up in your <form action="...url..."> tag
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, 'https://www.website.com/PassMarkFrame.aspx'); // use the URL that shows up in your <form action="...url..."> tag
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_exec($ch);
curl_close ($ch);
这是正确的语法吗?
上面做了更改,但仍然有相同的结果。我必须允许它存储Cookie吗? – 2012-02-02 15:55:34
是的,你需要允许cookies – pduersteler 2012-02-02 15:57:38
感谢您的帮助!它在设置cookie并摆脱curl_close后为我工作。 – 2012-02-02 16:09:38