Skip to content

Instantly share code, notes, and snippets.

@jackpoter
Created May 20, 2014 21:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackpoter/69fddf01fd5a789231ce to your computer and use it in GitHub Desktop.
Save jackpoter/69fddf01fd5a789231ce to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
import time, random
import urllib
import urllib2
import cookielib
usr = 'cee'
pwd = '490896040'
'''
POST /index.php/action/login HTTP/1.1
Host: ilvsx.im
User-Agent: Mozilla/5.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 0
Referer: http://ilvsx.im/admin/login.php?referer=http%3A%2F%2Filvsx.im%2Fadmin%2Findex.php
Cookie: PHPSESSID=
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 77
name=cee&password=490896040&referer=http%3A%2F%2Filvsx.im%2Fadmin%2Findex.php
'''
#login_url = 'http://ilvsx.im/admin/login.php'
login_url = 'http://ilvsx.im/index.php/action/login'
admin_url = 'http://ilvsx.im/admin/index.php'
stimeout=5
_cookie = cookielib.CookieJar()
cookie = urllib2.build_opener(urllib2.HTTPCookieProcessor(_cookie))
urllib2.install_opener(cookie)
#user_agents = [ 'Mozilla/5.0']
#user_agent = random.choice(user_agents)
user_agent = [ 'Mozilla/5.0']
headers = {"User-Agent": user_agent, "Referer": admin_url}
_data = {'name':usr, 'password':pwd, 'referer': admin_url, }
_data = urllib.urlencode(_data)
request = urllib2.Request(login_url, data=_data, headers=headers)
try:
req = urllib2.urlopen(request,timeout=stimeout)
fin = req.read()
except:
print 'wget login_url error'
f = open(r'login0','wb')
f.write(fin)
f.close()
_data = {}
_data = urllib.urlencode(_data)
request = urllib2.Request(admin_url, data=_data, headers=headers)
try:
req = urllib2.urlopen(request,timeout=stimeout)
fin = req.read()
except:
print 'wget admin_url error'
f = open(r'admin1','wb')
f.write(fin)
f.close()
print 'Done!'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment