Skip to content

Instantly share code, notes, and snippets.

@taojy123
Created February 2, 2015 07:33
Show Gist options
  • Save taojy123/392f2027ee37f103f28b to your computer and use it in GitHub Desktop.
Save taojy123/392f2027ee37f103f28b to your computer and use it in GitHub Desktop.
快捷申请21cn邮箱
#coding=utf8
import cookielib
import urllib2, urllib
import time
import re
import traceback
import time
import random
from PIL import Image
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
#opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj), urllib2.ProxyHandler({'http':"10.239.120.37:911"}))
opener.addheaders = [
('User-agent', 'Mozilla/5.0 (Windows NT 5.2) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1'),
]
def get_page(url, data=None):
resp = None
n = 0
while n < 3:
n = n + 1
try:
resp = opener.open(url, data, timeout=5)
page = resp.read()
return page
except:
#traceback.print_exc()
time.sleep(2)
print "Try after 2 seconds ..."
continue
raise Exception("Get page failed")
while True:
print "----------------"
mail = "abc123" + str(random.randint(1, 999999)).zfill(6)
print mail
url = "http://fmail.21cn.com/free"
p = get_page(url)
token = re.findall(r'id="token" value="(.*?)" type="hidden"', p)[0]
# print token
key = re.findall(r'name="userName_(.*?)"', p)[0]
# print key
while True:
url = "http://fmail.21cn.com/free/monikey?rnd=%d" % time.time()
p = get_page(url)
open("a.jpg", "wb").write(p)
Image.open("a.jpg").show()
vcode = raw_input("vcode:")
if vcode:
break
url = "http://fmail.21cn.com/free/dirty.checkValidCode"
formData = urllib.urlencode({'verifyCode' : vcode,
'token' : token,
})
p = get_page(url, formData)
print p
if "0" not in p:
continue
url = "http://fmail.21cn.com/free/free.register"
formData = urllib.urlencode({
"userName_" + key : mail,
"passwd_" + key : "aa123456",
"confirmPasswd_" + key : "aa123456",
"verifyCode_" + key : vcode,
"token" : token,
"agree2" : "y",
})
p = get_page(url, formData)
# print p
# open("aa.html", "w").write(p)
if "注册成功".decode("utf8").encode("gbk") in p:
open("mail.txt", "a").write(mail + "\n")
print "ok!"
else:
print p
print "failed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment