Created
October 6, 2013 13:55
-
-
Save flyfire/6854419 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # -*- coding: UTF-8 -*- | |
| from xml.dom import minidom | |
| from urllib import request | |
| #代理设置 | |
| #request.install_opener(request.build_opener(request.ProxyHandler( | |
| # {"http" : "http://192.168.60.250:8080"} | |
| #))); | |
| #用户名 | |
| user = ""; | |
| def loadPage(id=''): | |
| url = "http://api.fanfou.com/statuses/user_timeline.xml?id=%s&count=60&max_id=%s"%(user,id); | |
| print('LOAD:%s'%url); | |
| f = request.urlopen(url); | |
| dom = minidom.parse(f); | |
| f.close(); | |
| return dom; | |
| i=0; | |
| children = loadPage().documentElement.getElementsByTagName('status'); | |
| out = open('fanfou.backup.xml','w',encoding='utf8'); | |
| out.write('<?xml version="1.0" encoding="utf8"?>\n<statuses>\n'); | |
| while (not len(children)<60): | |
| if i>0: | |
| children=children[1:]; | |
| for st in children: | |
| i+=1; | |
| last=st.getElementsByTagName('id')[0].firstChild.data; | |
| out.write(st.toxml()); | |
| out.write('\n'); | |
| print("%d:%s"%(i,last)); | |
| children = loadPage(last).documentElement.getElementsByTagName('status'); | |
| out.write('</statuses>\n'); | |
| out.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment