#-*-coding:utf-8-*-
# Author: david.qi
# mail: [email protected]
import requests
import hashlib
import urllib
from bs4 import BeautifulSoup as bs
import re
email =''
pwd = ''
s = requests.session()
url = 'https://www.oschina.net/action/user/hash_login'
pwd1 = hashlib.sha1(pwd).hexdigest()
para = {'email': email,'pwd': pwd1, 'save_login': '1','verifyCode': ''}
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36',
'Upgrade-Insecure-Requests':1,
'X-Requested-With':'XMLHttpRequest',
'Content-Type':'application/x-www-form-urlencoded',
'Accept':'*/*',
'Accept-Language':'zh-CN,zh;q=0.8'}
r = requests.session()
s.post(url, data=para, headers=headers)
re = s.get('http://www.oschina.net', headers=headers)
soup = bs(re.text, 'html.parser')
print soup.findAll('div',{'id':'OSC_Userbar'})[0].select('em')[0].string