我正在尝试为需要登录到我的帐户以获取想要刮取的数据的站点编写一个刮取器。我认为问题出在网站期望登录数据的方式上,我不了解格式化该信息的正确方法。下面是我的代码,var_dump返回bool(false)。应该如何设置格式以便登录成功?
include "simple_html_dom.php";
$postFields = array(
"username" => "bbtestaccess@gmail.com", //This would be a valid username for the site.
"password" => "bbpassword1", //This would be a valid password for the site.
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://www.bodybuilding.com/profile/login");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postFields));
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_CAINFO, "/CAcert.pem");
$response = curl_exec($ch);
var_dump($response);