Google Reader...
这段时间 Google Reader 都好慢啊...
所以写了个 Google Reader 订阅网站的导出自动脚本...
导出大致分 2 步:
#1 访问 https://www.google.com/accounts/ClientLogin 以登录 Google Account
#2 访问 http://www.google.com/reader/subscriptions/export 导出对应的 Google Reader 订阅
第一步的说明:
这一步是要登录对应的 Google Account, 所以在 Post Data 里要填写对应的 mail 和 password 还有 service 等,具体参考下表.
------------------------------------------------------------------------------------
POST parameter name | POST parameter value
------------------------------------------------------------------------------------
service | 'reader' (!)
Email | your login
Passwd | your password
source | your client string identification (!)
continue | 'http://www.google.com/' (!)
------------------------------------------------------------------------------------
有 (!) 的是可选字段, 这个请求的回应会包括 3 个 ID 分别是 SID, LSID 和 Auth ...
只要把 SID 加入到之后的请求, google 就会把这些新的请求指向对应的 account 了.
第二步说明:
这一步是导出对应的请求,可以先用 Firebug 监视一下 Google Reader 自己是怎么做的,随后照着发协议就是了.我监视了一下,也没有啥花头,就把 SID 设到 cookie 里,在发就可以得到对应的了.
这个我监视的时候看的 (红框部分就是那个请求):
参考资料:
http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI
大致上我写了如下实现,把 mail 和 password 改一改,就可以用了...
把结果放到 stdout 可以重定向给其他程序...
导出的格式是 OPML (参考 http://en.wikipedia.org/wiki/OPML )
--------------------------------------------------------------------------------------------------------
#!/usr/bin/env python
import sys, os, string, urllib, urllib2, cookielib;
G_LOGIN = 'https://www.google.com/accounts/ClientLogin';
GREADER_EXPORT = 'http://www.google.com/reader/subscriptions/export';
DEFAULT_AGENT = "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90)";
G_ACCOUNT = 'you mail ????????';
G_ACCOUNT_PSW = 'you password ????';
def TestGReaderNodesExport() :
reqDat = {
'service' : 'reader',
'Email' : G_ACCOUNT,
'Passwd' : G_ACCOUNT_PSW,
'source' : 'GReaderTest',
'continue' : 'http://www.google.com/',
};
postData = urllib.urlencode(reqDat);
reqHdr = {'User-agent' : DEFAULT_AGENT };
# login to google
urlReq = urllib2.Request(G_LOGIN, postData, reqHdr);
urlFd = urllib2.urlopen(urlReq);
repData = urlFd.read();
# print(repData);
# parse sid
gSID = None;
gAuth = None;
SID_ID = 'SID=';
AUTH_ID = 'Auth=';
if SID_ID in repData :
sidBegin = repData.find(SID_ID);
sidEnd = repData.find('\n', sidBegin);
gSID = repData[sidBegin + len(SID_ID) : sidEnd];
if AUTH_ID in repData :
authBegin = repData.find(AUTH_ID);
authEnd = repData.find('\n', authBegin);
gAuth = repData[authBegin + len(AUTH_ID) : authEnd];
if None == gSID or None == gAuth :
print("login failed\n");
# print(gSID);
# print(gAuth);
# create cookie
cookie = cookielib.Cookie(version = 0,
name = 'SID', value = gSID, port = None, port_specified = False,
domain = '.google.com', domain_specified = True,
domain_initial_dot = True, path = '/reader/', path_specified = True,
secure = False, expires = '1600000000', discard = False,
comment = None, comment_url = None, rest = {});
cookieJar = cookielib.LWPCookieJar();
cookieJar.set_cookie(cookie);
# export google reader
reqHdr = {
'User-agent' : DEFAULT_AGENT,
};
urlReq = urllib2.Request(GREADER_EXPORT, None, reqHdr);
cookieJar.add_cookie_header(urlReq);
urlFd = urllib2.urlopen(urlReq);
result = urlFd.read();
print(result);
if __name__ == '__main__':
TestGReaderNodesExport();
所以写了个 Google Reader 订阅网站的导出自动脚本...
导出大致分 2 步:
#1 访问 https://www.google.com/accounts/ClientLogin 以登录 Google Account
#2 访问 http://www.google.com/reader/subscriptions/export 导出对应的 Google Reader 订阅
第一步的说明:
这一步是要登录对应的 Google Account, 所以在 Post Data 里要填写对应的 mail 和 password 还有 service 等,具体参考下表.
------------------------------------------------------------------------------------
POST parameter name | POST parameter value
------------------------------------------------------------------------------------
service | 'reader' (!)
Email | your login
Passwd | your password
source | your client string identification (!)
continue | 'http://www.google.com/' (!)
------------------------------------------------------------------------------------
有 (!) 的是可选字段, 这个请求的回应会包括 3 个 ID 分别是 SID, LSID 和 Auth ...
只要把 SID 加入到之后的请求, google 就会把这些新的请求指向对应的 account 了.
第二步说明:
这一步是导出对应的请求,可以先用 Firebug 监视一下 Google Reader 自己是怎么做的,随后照着发协议就是了.我监视了一下,也没有啥花头,就把 SID 设到 cookie 里,在发就可以得到对应的了.
这个我监视的时候看的 (红框部分就是那个请求):
![]() |
参考资料:
http://code.google.com/p/pyrfeed/wiki/GoogleReaderAPI
大致上我写了如下实现,把 mail 和 password 改一改,就可以用了...
把结果放到 stdout 可以重定向给其他程序...
导出的格式是 OPML (参考 http://en.wikipedia.org/wiki/OPML )
--------------------------------------------------------------------------------------------------------
#!/usr/bin/env python
import sys, os, string, urllib, urllib2, cookielib;
G_LOGIN = 'https://www.google.com/accounts/ClientLogin';
GREADER_EXPORT = 'http://www.google.com/reader/subscriptions/export';
DEFAULT_AGENT = "Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90)";
G_ACCOUNT = 'you mail ????????';
G_ACCOUNT_PSW = 'you password ????';
def TestGReaderNodesExport() :
reqDat = {
'service' : 'reader',
'Email' : G_ACCOUNT,
'Passwd' : G_ACCOUNT_PSW,
'source' : 'GReaderTest',
'continue' : 'http://www.google.com/',
};
postData = urllib.urlencode(reqDat);
reqHdr = {'User-agent' : DEFAULT_AGENT };
# login to google
urlReq = urllib2.Request(G_LOGIN, postData, reqHdr);
urlFd = urllib2.urlopen(urlReq);
repData = urlFd.read();
# print(repData);
# parse sid
gSID = None;
gAuth = None;
SID_ID = 'SID=';
AUTH_ID = 'Auth=';
if SID_ID in repData :
sidBegin = repData.find(SID_ID);
sidEnd = repData.find('\n', sidBegin);
gSID = repData[sidBegin + len(SID_ID) : sidEnd];
if AUTH_ID in repData :
authBegin = repData.find(AUTH_ID);
authEnd = repData.find('\n', authBegin);
gAuth = repData[authBegin + len(AUTH_ID) : authEnd];
if None == gSID or None == gAuth :
print("login failed\n");
# print(gSID);
# print(gAuth);
# create cookie
cookie = cookielib.Cookie(version = 0,
name = 'SID', value = gSID, port = None, port_specified = False,
domain = '.google.com', domain_specified = True,
domain_initial_dot = True, path = '/reader/', path_specified = True,
secure = False, expires = '1600000000', discard = False,
comment = None, comment_url = None, rest = {});
cookieJar = cookielib.LWPCookieJar();
cookieJar.set_cookie(cookie);
# export google reader
reqHdr = {
'User-agent' : DEFAULT_AGENT,
};
urlReq = urllib2.Request(GREADER_EXPORT, None, reqHdr);
cookieJar.add_cookie_header(urlReq);
urlFd = urllib2.urlopen(urlReq);
result = urlFd.read();
print(result);
if __name__ == '__main__':
TestGReaderNodesExport();