我正在尝试使用curl登录到apollohouseware .co.uk网站。我想在登录后检索价格信息。我是卷发新手,所以需要帮助。当我发布数据时,它显示无效的用户名和密码,但使用浏览器登录时相同的凭据正在工作。
//username and password of account
$username = trim(' ');
$password = trim(' ');
//login form action url ///
$url="https://apollohousewares.co.uk/members/login/";
$postinfo = "username=".urlencode($username)."&password=".urlencode($password);
$cookie_file_path = "cookie.txt";
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIE, "cookiename=0");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $_SERVER['REQUEST_URI']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postinfo);
curl_exec($ch);
//page with the content I want to grab
curl_setopt($ch, CURLOPT_URL, "https://apollohousewares.co.uk/members/customers/target/home/");
echo $html = curl_exec($ch);
curl_close($ch);
如有任何帮助,不胜感激。
同时,我的cookie.txt是可写的并且可以工作
在浏览器中打开网站,在"网络"中点击登录按钮时,找到点击的URL。选项卡的"开发人员工具"。窗口。右键单击该行,选择"复制为cURL"这将是完整的curl命令,包含所有参数和post主体。这样您就可以看到用户名和密码是如何编码的。