使用 curl 登录并获取会话 [英] login with curl and get session

查看:35
本文介绍了使用 curl 登录并获取会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我需要以某种方式获得最高的区域兴趣和兴趣

hello i need somehow to get top Regional interest and interest over time from

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 导出数据?或者别的

so i found out that we have to login to export data can anybody give me an example doing this with our google username and password? maybe using curl to export the data? or something else

感谢关注

亚当斋月

推荐答案

为了快速起见,我使用了我的 xhttp 类 这是一个 curl 包装器,我认为代码很容易理解.

Just to be quick about it, I used my xhttp class which is a curl wrapper, and I think the code is easy enough to follow.

<?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但我不确定结果是否是您想要的.

The result is at: http://codecri.me/apps/test/test.google.trends.php But I'm not sure if the result is what you are looking for.

这篇关于使用 curl 登录并获取会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆