你好,我需要以某种方式获得最高区域的兴趣和随着时间的推移的兴趣
http://www.google.com/trends?q=lingerie+&ctab=0&geo=id&date=all&sort=0
或更好
http://www.google.com/insights/search/#q=lingerie&geo=ID&cmpt=q
所以我发现我们必须登录才能导出数据有人能给我一个使用我们的谷歌用户名和密码执行此操作的示例吗?也许使用curl来导出数据?或者其他东西
感谢您的关注
亚当·拉马丹
最佳答案
为了快速起见,我使用了我的 xhttp class这是一个curl 包装器,我认为代码很容易理解。
<?php
header('content-type: text/plain');
// Set account login info
$data['post'] = array(
'accountType' => 'HOSTED_OR_GOOGLE', // indicates a Google account
'Email' => '', // full email address
'Passwd' => '',
'service' => 'trendspro', // Name of the Google service
'source' => 'codecri.me-example-1.0' // Application's name, e.g. companyName-applicationName-versionID
);
$response = xhttp::fetch('https://www.google.com/accounts/ClientLogin', $data);
// Test if unsuccessful
if(!$response['successful']) {
echo 'response: '; print_r($response);
die();
}
// Extract SID
preg_match('/SID=(.+)/', $response['body'], $matches);
$sid = $matches[1];
// Erase POST variables used on the previous xhttp call
$data = array();
// Set the SID in cookies
$data['cookies'] = array(
'SID' => $sid
);
$response = xhttp::fetch('http://www.google.com/insights/search/overviewReport?q=lingerie&geo=ID&cmpt=q&content=1&export=1', $data);
// CSV data in the response body
echo $response['body'];
?>
结果位于:http://codecri.me/apps/test/test.google.trends.php 但我不确定结果是否是您想要的。
关于php - 使用curl登录并获取 session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6101151/