Skip to content

Instantly share code, notes, and snippets.

Created November 25, 2008 07:47
Show Gist options
  • Save anonymous/28845 to your computer and use it in GitHub Desktop.
Save anonymous/28845 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# encoding: utf-8
from twill import *
import urllib2,re
USERNAME = 'YOUR USERNAME'
PASSWORD = 'YOUR PASSWORD'
BLOG_LIST = [
'http://blog.sina.com.cn/pp9233',
'http://blog.sina.com.cn/u/1228647457',
'http://blog.sina.com.cn/u/1547740912',
]
def getuid(url):
"""
>>> getuid('http://blog.sina.com.cn/pp9233')
'1348443601'
>>> getuid('http://blog.sina.com.cn/u/1228647457')
'1228647457'
>>> getuid('http://blog.sina.com.cn/u/1547740912')
'1547740912'
"""
html = urllib2.urlopen(url).read()
uid=re.findall(r'var \$uid = "(\S+)";',html)
try:
return uid[0]
except:
return "error"
def login():
return '''
go http://login.sina.com.cn/hd/signin.php?entry=blog
showforms
fv 1 username %(username)s
fv 1 password %(password)s
showforms
submit 0
'''
def guest():
return '''
go http://v.space.sina.com.cn/visitor/add.php?prod=1&uid=%(uid)s&var=newVisitor
'''
def main():
data = {'username':USERNAME,'password':PASSWORD}
cmd=login()%data
print cmd
print execute_string(cmd)
for blog in BLOG_LIST:
uid=getuid(blog)
print "blog uid is: ",uid
cmd=guest()%{"uid":uid}
print execute_string(cmd)
if __name__ == '__main__':
import doctest
# doctest.testmod()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment