我正在尝试登录一个网站,然后转到一个链接,然后提交一个表单以获取所需的数据。我想用 cURL 来做。我已成功登录网站。登录将我重定向到个人资料页面。
现在我需要点击链接,然后提交表格!但是当我使用 CURL 执行此操作时,会话无效。我在用于存储创建的 cookie的 cookie.txt 文件中获取 JSESSIONID 。我看到的所有示例都只是关于登录网站或只是提交注册表单。这只是一个POST请求!
成功登录并存储 cookie 后,如何转到另一个链接,然后使用 curl 提交另一个表单?
我使用 WAMP 作为我的本地服务器。
<?php
$username="myusername";
$password="mypassword";
$url="http://onlinelic.in/LICEPS/Login/webLogin.do";
$referer = "http://onlinelic.in/epslogin.htm";
$postdata = "portlet_5_6{actionForm.userName}=".$username."&portlet_5_6{actionForm.password}=".$password;
$cookie = "cookie.txt" ;
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0");
curl_setopt($ch,CURLOPT_COOKIESESSION,false);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_REFERER, $referer);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
logIntoLocator();
curl_close($ch);
function logIntoLocator()
{
$pincode = "731234";
$locatorType = "P";
$url = "http://onlinelic.in/LICEPS/appmanager/Customer/CustomerHome?_nfpb=true&_windowLabel=Cust_Agent_Locator_portlet_25_2&Cust_Agent_Locator_portlet_25_2_actionOverride=%2Fportlets%2Fvisitor%2FAgentLocator%2Flocating";
$referer = "https://customer.onlinelic.in/LICEPS/appmanager/Customer/CustomerHome?_nfpb=true&_windowLabel=CustomerLocatorsPortlet_1&_cuid=RC_t_832059&_pagechange=AgentLocator";
$postData = "Cust_Agent_Locator_portlet_25_2wlw-radio_button_group_key:{actionForm.agentRadioOption}=".$locatorType."&Cust_Agent_Locator_portlet_25_2{actionForm.agentOption}=".$pincode;
$cookie = "cookie.txt" ;
$agentCurl = curl_init();
curl_setopt ($agentCurl, CURLOPT_URL, $referer);
curl_setopt ($agentCurl, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt ($agentCurl, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20100101 Firefox/13.0");
curl_setopt($agentCurl,CURLOPT_COOKIESESSION,true);
curl_setopt ($agentCurl, CURLOPT_TIMEOUT, 60);
curl_setopt ($agentCurl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($agentCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($agentCurl, CURLOPT_REFERER, $referer);
curl_setopt ($agentCurl, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($agentCurl, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($agentCurl, CURLOPT_POSTFIELDS, $postData);
curl_setopt ($agentCurl, CURLOPT_POST, 1);
$result = curl_exec ($agentCurl);
echo $result;
}
如果您想尝试一下,用户名是“manashch1”,密码是“nokia1105*”。在那里登录并进入 AgentLocator,在那里你可以输入密码为 731234 并获取所需的数据。