模拟登录脚本之搬瓦工bandwagonhost
老早写的,都忘了当初想干啥了。。。。 半成品,留个坑,待填。 #!/usr/bin/env python # encoding: utf-8 import cookielib import requests def http_send(url, post_data='', **kwargs): cookie_handler = cookielib.MozillaCookieJar('cookie.txt') try: cookie_handler.load(ignore_discard=1) except cookielib.LoadError, e: print e + "new cookie file" headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36'} if post_data: req = requests.post(url, data=post_data, cookies=cookie_handler) else: req = requests.get(url) print req.headers for c in req.cookies: cookie_handler.set_cookie(c) cookie_handler.save(ignore_discard=1) return req.content if __name__ == '__main__': # init cookie print http_send('http://localhost/clientarea....