Skip to content

Instantly share code, notes, and snippets.

@aligo
Created August 3, 2012 01:59
Show Gist options
  • Save aligo/3243405 to your computer and use it in GitHub Desktop.
Save aligo/3243405 to your computer and use it in GitHub Desktop.
miao2
from urllib import urlretrieve
from tesseract import image_to_string
import requests, random, time, re, Image
start_point = time.time()
def r_timestamp():
return str(int(time.time()*1000))
miao = 0
i = int(random.random() * 65535 * 65535)
captcha_filename = 'captcha' + str(i) + '.jpg'
p_captcha_id = re.compile('.*"retval":"(\w+)".*')
p_captcha = re.compile('^\w{5}$')
p_success = re.compile('.*"success":true.*')
s = requests.session()
while True:
i = i + 1
while True:
try:
r = s.get('http://www.gewara.com/getCaptchaId.xhtml?r=' + r_timestamp())
captcha_id = p_captcha_id.match(r.text).group(1)
except AttributeError, e:
print 'the server has been fucked over'
time.sleep(10)
continue
break
while True:
try:
captcha_url = 'http://www.gewara.com/captcha.xhtml?captchaId=' + captcha_id + '&r=' + r_timestamp()
urlretrieve(captcha_url, captcha_filename)
captcha = image_to_string(Image.open(captcha_filename))
captcha = captcha.encode('ascii','ignore')
captcha = captcha.replace(' ', '')
if not p_captcha.match(captcha): continue
except UnicodeDecodeError, e: continue
except IOError, e: continue
postdata = {
'captcha' : captcha,
'captchaId' : captcha_id,
'email' : 'miao' + str(i) + '@miao.com',
'nickname' : 'miao' + str(i),
'password' : 'miaomiao',
'repassword': 'miaomiao',
'service' : 'on'
}
r = s.post('http://www.gewara.com/savereg.xhtml', data=postdata)
if p_success.match(r.text): break
r = s.get('http://www.gewara.com/subject/ajax/supportCatPic.xhtml?id=1343197973701XZpAh')
if p_success.match(r.text):
miao = miao + 1
print 'miao~: ' + str(miao) + ' / time: ' + str(time.time() - start_point)
s.get('http://www.gewara.com/cas/logout.xhtml?ptn=smp')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment