Показать сообщение отдельно

  #6  
Старый 23.08.2009, 15:48
e4key
Новичок
Регистрация: 24.07.2009
Сообщений: 24
Провел на форуме:
71052

Репутация: 5
По умолчанию

При получении капчи нужно сохранить сессию, а затем отправить капчу с этой сессией. Вот я делал на питоне для free-uin.org:

Код:
#!/usr/bin/python
# -*- coding: utf-8 -*-

import re
import time
import urllib
import urllib2
import httplib
import cookielib

def load_captcha():
    global cookies
    cookiejar = cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
    image = opener.open('http://www.free-uin.org/r/img.php?regen=y').read()
    for i in cookiejar:
        cookies = 'PHPSESSID=' + i.value + ';SMFCookie988=a%3A4%3A%7Bi%3A0%3Bs%3A4%3A%227054%22%3Bi%3A1%3Bs%3A40%3A%22c06d8bdaaa9f9f459b37534288532ec5b36d8c51%22%3Bi%3A2%3Bi%3A1436452120%3Bi%3A3%3Bi%3A0%3B%7D'
    return image

def main():
    while True:
        image = load_captcha()
        key = 'key_here'
        results = open('uins.txt', 'w')
    
        cap_id = send_cap(key, image)
        if not cap_id:
            print 'Not send...'
            return
        
        status, text= get_cap_text(key, cap_id)
        if status == 'OK':
            data = urllib.urlencode({'code': text, 'btnI': ''})
            req = urllib2.Request('http://www.free-uin.org/r/mnlxswrt.php', data)
            req.add_header('Cookie', cookies)
            page = urllib2.urlopen(req).read()
            uin = re.findall('([0-9]+;[a-zA-Z0-9]+)\n', page)
            if len(uin) != 0:
                print 'Hehe: ' + uin[0]
                results.write(uin[0] + '\n')
                results.fluch()
            else:
                if len(re.findall('<br><br> <a', page)) != 0:
                    bad_url = 'http://anti-captcha.com/res.php'
                    bad_data = urllib.urlencode({'key': key, 'action': 'reportbad', 'id': cap_id})
                    bad = urllib.urlopen(bad_url, bad_data)
                    print 'Incorrect code!'
                else:
                    print 'Do not lucky ...'

def get_cap_text(key, cap_id):
	time.sleep(5)
	res_url = 'http://ac-service.info/res.php'
	res_url += "?" + urllib.urlencode({'key': key, 'action': 'get', 'id': cap_id})
	while 1:
		res = urllib.urlopen(res_url).read()
		if res == 'CAPCHA_NOT_READY':
			time.sleep(1)
			continue
		break
	
	res = res.split('|')
	if len(res) == 2:
		return tuple(res)
	else:
		return ('ERROR', res[0])

def send_cap(key, data):
	boundary = '----------OmNaOmNaOmNamo'
	body = '''--%s
Content-Disposition: form-data; name="method"

post
--%s
Content-Disposition: form-data; name="key"

%s
--%s
Content-Disposition: form-data; name="file"; filename="capcha.jpg"
Content-Type: image/pjpeg

%s
--%s--

''' % (boundary, boundary, key, boundary, data, boundary)
	headers = {'Content-type' : 'multipart/form-data; boundary=' + boundary}
	h = httplib.HTTPConnection('ac-service.info')
	h.request("POST", "/in.php", body, headers)
	resp = h.getresponse()
	data = resp.read()
	h.close()
	if resp.status == 200:
		cap_id = int(data.split('|')[1])
		return cap_id
	else:
		return False

if __name__ == '__main__':
    main()
 
Ответить с цитированием