我想写一个PHP脚本:
一个。登录到网站 B.导航到特定页面(这是一个csv文件下载) C.将结果存储在字符串中。
类似的东西:
$site->connect("dashboard.site.com");
$site->post_vars(array("username"=>"mike","password"=>"2345");
$csv_file = $site->download("dashboard.site.com/file.csv");
我已经阅读了关于snoopy类的内容,但文档似乎不存在,所以我无法确定它是否可以做到。
答案 0 :(得分:0)
我想出了如何使用Curl来做到这一点。我自己的登录名和密码以及商家组当然隐藏在此代码中。但是这里是如何做到的:我希望这可以帮助处于相同情况的任何人。
$cookie_jar = tempnam('/tmp','cookie');
// log in
$c = curl_init('https://dashboard.powerreviews.com/dashboard/login');
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, false);
$page = curl_exec($c);
curl_close($c);
$post_fields = array("j_username" => "USERNAME", "j_password" => "PASSWORD", "command"=>"Login");
$post_data = http_build_query($post_fields);
$c = curl_init('https://dashboard.powerreviews.com/process_login');
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $post_data);
$page = curl_exec($c);
curl_close($c);
// switch to Reviews Account
$c = curl_init('https://dashboard.powerreviews.com/programs/epc?accessMerchantGroup=xxxxx');
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);
$csv_file = curl_exec($c);
curl_close($c);
// download RA unsubscribes
$c = curl_init('https://dashboard.powerreviews.com/dashboard/unsubscribes.csv');
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_COOKIEFILE, $cookie_jar);
curl_setopt($c, CURLOPT_COOKIEJAR, $cookie_jar);
$csv_file = curl_exec($c);
curl_close($c);
echo $csv_file;