Created
November 3, 2014 07:55
-
-
Save qhhonx/f1548fa308c95db95171 to your computer and use it in GitHub Desktop.
weibo.cn登录助手(Login assist for weibo.cn)
This file contains 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
# coding=utf8 | |
from pyquery import PyQuery as pq | |
import requests | |
class Weibo(object): | |
""""Login Assist for weibo.cn""" | |
def __init__(self, username, password): | |
self.username = username | |
self.password = password | |
self.session = requests.Session() | |
self.session.headers.update({ | |
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2202.3 Safari/537.36' | |
}) | |
def login(self): | |
url = 'http://login.weibo.cn/login/' | |
r = self.session.get(url) | |
d = pq(r.text.encode('utf8')) | |
action = d('form').attr.action | |
data = {} | |
inputs = d('form input') | |
data[inputs[0].name] = self.username # mobile | account name | |
data[inputs[1].name] = self.password # password | |
for input in inputs[2:]: | |
data[input.name] = input.value | |
r = self.session.post(url + action, data=data) | |
def get(self, url): | |
return self.session.get(url).text.encode('utf8') | |
if __name__ == '__main__': | |
weibo = Weibo('user@example.com', 'password') | |
weibo.login() | |
print weibo.get('http://weibo.cn') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment