def parse(self, response):

        # Put your DBC account username and password here.
        username = '******'
        password = '******'
        # Use deathbycaptcha.HttpClient for HTTP API.
        client = deathbycaptcha.SocketClient(username, password)
        try:
            balance = client.get_balance()
            print 'Balance: %f' % (balance)
            #return
            urlImg = response.xpath(
                '//img[@alt="CAPTCHA"]/@src').extract_first()
            print u'Get UrlImg:' + urlImg
            url = response.urljoin(urlImg)
            print u'url join:' + url
            captcha_file_name = "C:/ZZZZ01.jpg"
            timeout = 10
            urllib.urlretrieve(url, captcha_file_name)
            print u'Марк 03'

            # Put your CAPTCHA file name or file-like object, and optional
            # solving timeout (in seconds) here:
            captcha = client.decode(captcha_file_name, timeout)
            if captcha:
                # The CAPTCHA was solved; captcha["captcha"] item holds its
                # numeric ID, and captcha["text"] item its text.
                print "CAPTCHA %s solved: %s" % (captcha["captcha"],
                                                 captcha["text"])
                view(response)

        except:
            print "Oops!  That was no valid number.  Try again..."
示例#2
0
    def getCaptcha(image, image_data):
        # 通过DeathByCaptcha 方式获取验证码
        client = deathbycaptcha.SocketClient('', '')
        try:
            captcha = client.decode(image, 60)
            if captcha:
                logger.debug("CAPTCHA %s solved: %s" %
                             (captcha["captcha"], captcha["text"]))
                logger.debug(str(captcha["text"]))
                if 'no clear' == str(captcha["text"]):
                    raise Exception("cannot captcha this picture")
                return captcha
        except Exception as e:
            logger.error("DEATH BY CAPTCHA exception:" + str(e))

            # 通过CaptchaByPass 方式获取验证码
            bypass_key = config.CaptchaByPassKey
            con = base64.b64encode(image_data)
            logger.debug("Decoding.")
            try:
                ret = bypass_api.bc_submit_captcha(bypass_key, con)
                logger.debug("Using the decoded %s : %s." %
                             (ret['TaskId'], ret['Value']))
                logger.debug("There are " +
                             bypass_api.bc_get_left(bypass_key) +
                             " credits left on this key.")
                captcha = dict()
                captcha['text'] = ret['Value']
                if 'test' == str(captcha['text']):
                    raise Exception('captcha error')
                return captcha
            except Exception as e:
                logger.debug("BYPASS exception:" + str(e))
        return None
示例#3
0
def solve_iowa_captcha(site_key_stripped):
    dbc_page_params = {
        'googlekey': site_key_stripped,
        'pageurl':
        'https://www.iowacourts.state.ia.us/ESAWebApp/TrialSimpFrame',
        'proxy': '',
        'proxytype': ''
    }

    dbc_url = 'http://api.dbcapi.me/api/captcha'
    dbc_client = deathbycaptcha.SocketClient('jborowitz', 'MDcHvM*$5nsW2Kf')

    try:
        balance = dbc_client.get_balance()
        print('starting to solve captcha: %s' % datetime.datetime.now())
        captcha = dbc_client.decode(type=4,
                                    token_params=json.dumps(dbc_page_params))
        print('finished solving captcha: %s' % datetime.datetime.now())
        if captcha:
            print('Captcha solved!')
            print("CAPTCHA %s solved: %s" %
                  (captcha["captcha"], captcha["text"]))
        else:
            print('Captcha failed')
            raise KeyError("Failed Captcha")
        print('Found balance: %s' % balance)
        # dbc_params['token_params'] = json.dumps(dbc_page_params)
    except deathbycaptcha.AccessDeniedException as e:
        print(e)
    return captcha
示例#4
0
 def __init__(self, url, img):
     self.url = url
     self.img = img
     self.client = deathbycaptcha.SocketClient(settings.CAPTCHAR_USERNAME,
                                               settings.CAPTCHAR_PWD)
     self.captcha = None
     self.retorno = None
     self.retorno_get = None
示例#5
0
 def __init__(self):
     print 'Starting browser'
     self.browser = webdriver.Firefox()
     self.browser.set_page_load_timeout(5)
     self.browser.set_window_size(960, 1080)
     self.browser.set_window_position(960, 0)
     self.dbc_client = dbc.SocketClient('hyperion_blue', 'b0000000000')
     self.formail = Formail()
     self.faker = Faker()
def solve_captcha(username, password, captcha_file):
    client = deathbycaptcha.SocketClient(username, password)
    try:
        # balance = client.get_balance()
        # print balance
        captcha = client.decode(captcha_file)
        if captcha:
            print("CAPTCHA %s solved: %s" %
                  (captcha["captcha"], captcha["text"]))
            return captcha["text"]
    except deathbycaptcha.AccessDeniedException:
        exit(1)
def get_g_captcha_response(url, retries=3):
    resp = requests.get(url)
    soup = BeautifulSoup(resp.text, "html.parser")
    data_sitekey = soup.find("div", {"class": "g-recaptcha"})["data-sitekey"]

    username = os.environ.get("DBC_USERNAME", "PUT_YOUR_USERNAME_HERE")
    password = os.environ.get("DBC_PASSWORD", "PUT_YOUR_PASSWORD_HERE")

    # Put the proxy and reCaptcha token data

    Captcha_dict = {
        "googlekey": data_sitekey,
        "pageurl": url,
    }

    # Create a json string
    json_Captcha = json.dumps(Captcha_dict)

    print("Retrieving CAPTCHA - normally takes about 30 seconds")
    client = deathbycaptcha.SocketClient(username, password)
    # to use http client client = deathbycaptcha.HttpClient(username, password)
    # client = deathbycaptcha.HttpClient(username, password)

    try:
        balance = client.get_balance()
        print(f"CAPTCHA credit balance: {balance}")

        # Put your CAPTCHA type and Json payload here:
        captcha = client.decode(type=4, token_params=json_Captcha)
        if captcha:
            # The CAPTCHA was solved; captcha["captcha"] item holds its
            # numeric ID, and captcha["text"] item its list of "coordinates".
            print("CAPTCHA %s solved: %s" %
                  (captcha["captcha"], captcha["text"]))
            return captcha["text"]

            if "":  # check if the CAPTCHA was incorrectly solved
                client.report(captcha["captcha"])
        elif retries > 0:
            print(f"Retrying. {retries} retries left")
            get_g_captcha_response(url, -1)
    except deathbycaptcha.AccessDeniedException:
        # Access to DBC API denied, check your credentials and/or balance
        print("error: Access to DBC API denied," +
              "check your credentials and/or balance")
示例#8
0
def DBCcaptcha(cap_name):
    usr = "******"
    psw = "#####"
    captcha_file_name = cap_name
    timeout = 120
    client = deathbycaptcha.SocketClient(usr, psw)

    try:
        alance = client.get_balance()
        captcha = client.decode(captcha_file_name, timeout)
        if captcha:

            print "CAPTCHA %s resuelto: %s" % (captcha["captcha"], captcha["text"])

    except deathbycaptcha.AccessDeniedException:
        print('fallo login')#todo: que pruebe con otras credenciales si falla

    return captcha
示例#9
0
def solveCaptcha(challenge):
	# Put your DBC account username and password here.
    # Use deathbycaptcha.HttpClient for HTTP API.

	username = "******"
	password = "******"
	captcha_file_name = challenge + ".png"
	timeout = 99

	client = deathbycaptcha.SocketClient(username, password)
	try:
		balance = client.get_balance()

		# Put your CAPTCHA file name or file-like object, and optional
		# solving timeout (in seconds) here:
		captcha = client.decode(captcha_file_name, timeout)
		if captcha:
			return captcha["text"]
	except deathbycaptcha.AccessDeniedException:
	    # Access to DBC API denied, check your credentials and/or balance
	    #print "error with death by captcha"
	    return "failed"
示例#10
0
def solveCaptcha(captcha_file_name, timeout=60):
    # Put your DBC account username and password here.
    # Use deathbycaptcha.HttpClient for HTTP API.
    client = deathbycaptcha.SocketClient(unm, p)
    try:
        balance = client.get_balance()
        print "balance: " + str(balance)

        # Put your CAPTCHA file name or file-like object, and optional
        # solving timeout (in seconds) here:
        captcha = client.decode(captcha_file_name, timeout)
        if captcha:
            # The CAPTCHA was solved; captcha["captcha"] item holds its
            # numeric ID, and captcha["text"] item its text.
            print "CAPTCHA %s solved: %s" % (captcha["captcha"],
                                             captcha["text"])
            return captcha['text']
            #
            # if ...:  # check if the CAPTCHA was incorrectly solved
            #     client.report(captcha["captcha"])
    except deathbycaptcha.AccessDeniedException:
        raise
示例#11
0
    def __init__(self):
        print '-' * 10, 'CCD v(1.0)', '-' * 10

        # zeroes the file
        fileName = "CCD/Reports/CCD-%s.json" % (Yesterday)
        if (os.path.exists(fileName) and os.path.getsize(fileName) > 0):
            f = open(fileName, 'w').close()

        # Put your DBC account username and password here.
        username = '******'
        password = '******'
        # Use deathbycaptcha.HttpClient for HTTP API.
        client = deathbycaptcha.SocketClient(username, password)
        try:
            balance = client.get_balance()
            print 'Balance: %f' % (balance)
            urlImg = response.xpath(
                '//img[@alt="CAPTCHA"]/@src').extract_first()
            url = response.urljoin(urlImg)
            urllib.urlretrieve(url, "C:/ZZZZ01.jpg")
        except:
            print "Oops!  That was no valid number.  Try again..."
示例#12
0
文件: test.py 项目: aldslvda/crawler
import deathbycaptcha
import traceback
import json

# Put your DBC account username and password here.
# Use deathbycaptcha.HttpClient for HTTP API.
client = deathbycaptcha.SocketClient('bm0546', 'vobile123')
try:
    balance = client.get_balance()

    # Put your CAPTCHA file name or file-like object, and optional
    # solving timeout (in seconds) here:
    captcha = client.decode('vcode_cut.jpg', 10)
    if captcha:
        # The CAPTCHA was solved; captcha["captcha"] item holds its
        # numeric ID, and captcha["text"] item its text.
        print json.dumps(captcha)
        print "CAPTCHA %s solved: %s" % (captcha["captcha"], captcha["text"])

        #if ...:  # check if the CAPTCHA was incorrectly solved
        #    client.report(captcha["captcha"])
except deathbycaptcha.AccessDeniedException:
    traceback.print_exc()
    # Access to DBC API denied, check your credentials and/or balance
示例#13
0
    # change frame
    # driver.switch_to.frame("displayCaptcha")

    # download image/captcha
    # img = driver.find_element_by_xpath(".//*[@id='captcha']")
    # print(img)
    # get_captcha(driver, img, "RandomTxt.jpg")

    ########################################################
    # Death by captcha start
    ########################################################

    # Put your DBC account username and password here.
    # Use deathbycaptcha.HttpClient for HTTP API.
    client = deathbycaptcha.SocketClient('username', 'password')
    try:
        balance = client.get_balance()

        # Put your CAPTCHA file name or file-like object, and optional
        # solving timeout (in seconds) here:
        captcha = client.decode("RandomTxt.jpg")
        if captcha:
            # The CAPTCHA was solved; captcha["captcha"] item holds its
            # numeric ID, and captcha["text"] item its text.
            print("CAPTCHA %s solved: %s" %
                  (captcha["captcha"], captcha["text"]))

            if ...:  # check if the CAPTCHA was incorrectly solved
                client.report(captcha["captcha"])
    except deathbycaptcha.AccessDeniedException:
示例#14
0
        stdout = yield tornado.gen.Task(self.popen, cmd)
        if re.search("OK", stdout):
            res = {"token": stdout.split(" ")[1]}
        else:
            res = {"error": stdout}
        self.write(json.dumps(res))
        self.finish()

    def popen(self, cmd, callback):
        stdout = os.popen(cmd).read()
        return callback(stdout)


import deathbycaptcha

captcha_client = deathbycaptcha.SocketClient("cockupyourbumper", "nadine")


# Perform captha resolution when VK prompts
class VKCaptchaHandler(tornado.web.RequestHandler):
    @tornado.gen.engine
    @tornado.web.asynchronous
    def get(self, sid):
        self.set_header("Content-Type", "application/json")
        url = "http://api.vk.com/captcha.php?sid=" + sid
        getReq = tornado.httpclient.HTTPRequest(url)
        res = yield tornado.gen.Task(async_client.fetch, getReq)
        fn = "/tmp/" + uuid4().hex + ".jpg"
        with open(fn, "wb") as f:
            f.write(res.body)
        captcha = yield tornado.gen.Task(self.solveCaptcha, fn)
示例#15
0
def data_scrapping(args, save_data=True):
    try:
        #Step 1: Read the CSV and run all over the companies
        symbols = pd.read_csv(args.symbol)
        df_results = {}
        for sym in symbols["Symbols"]:
            local_attempt = 0
            empty = True
            while local_attempt < args.attempts and empty:
                # Create the tempfile
                tmp_path = tempfile.mkdtemp()
                options = webdriver.ChromeOptions()
                options.add_argument("download.default_directory=" + tmp_path)
                prefs = {
                    'download.default_directory': tmp_path
                }
                options.add_experimental_option('prefs', prefs)
                # initializite the driver
                driver = webdriver.Chrome(options=options)
                delay = args.time
                driver.get("http://fundamentus.com.br/balancos.php?papel=" +
                           str(sym))
                WebDriverWait(driver, delay).until(
                    EC.presence_of_element_located((By.ID, 'containerMenu')))
                # Get captcha
                with open('captcha.png', 'wb') as file:
                    file.write(
                        driver.find_element_by_xpath(
                            '/html/body/div[1]/div[2]/form/img').
                        screenshot_as_png)

                # Send the captcha to the DeathByCaptcha
                username = args.username
                password = args.password
                # Send the captcha
                client = deathbycaptcha.SocketClient(username, password)
                captcha = client.decode("captcha.png", 15)
                if captcha is not None:
                    # Get the solution
                    solution = captcha["text"]
                    # Find the text box
                    web_elem = driver.find_element("name", "codigo_captcha")
                    # Send the captcha results
                    web_elem.send_keys(solution)
                    # Request the data_scraping
                    button = driver.find_element("name", "submit")
                    # Click the button
                    button.click()
                    # Sleep and wait for the download
                    time.sleep(args.time)
                    driver.close()
                    driver.quit()

                    #Extract the zip file
                    zip_file = glob.glob(tmp_path + "/" + "*.zip")

                    #Make sure that something was downloaded
                    local_attempt = local_attempt + 1
                    if len(zip_file) > 0: empty = False
                else:
                    empty = True
                    local_attempt = local_attempt + 1

            #Get the name (bal_Empresa.zip)
            if Path(zip_file[0]).name == "bal_Empresa.zip":
                empty == True
            else:
                # Sleep and wait for zip extract
                time.sleep(args.time)
                with zipfile.ZipFile(zip_file[0], 'r') as zip_ref:
                    zip_ref.extractall(tmp_path + "/")

                # Sleep and wait for zip extract
                time.sleep(args.time)

                # List all XLS files
                xls_file = glob.glob(tmp_path + "/" + "*.xls")

                # Read all sheets in a PandasDataFrame
                fund_dict = pd.read_excel(xls_file[0],
                                          sheet_name=None,
                                          header=None,
                                          skiprows=1)

                transposed_df = transpose_df(fund_dict)
                #Save results
                df_results[sym] = transposed_df
            if empty == True:
                print("ERROR: Symbol: " + sym + " was not downloaded.")
            else:
                print("OK: Symbol: " + sym + " was downloaded.")
    except Exception as e:
        print(str(e))

    #Save the results
    if save_data:
        pickle.dump(df_results, open("../data/all_data.pkl", "wb"))
    else:
        return df_results
示例#16
0
    md5 = Functions.SortMD5Hashs(
        md5, 60)  # Sort the hashs by group in a multi-dimensional list
    DBC_Logged = False  # DeathByCaptcha account logged in boolean

    DBC = True  # Are we goint to use DeathByCaptcha ?
    client = None  # DeathByCaptcha socket client

    while not DBC_Logged and DBC is True:
        DBC = Functions.confirm(
            "Would you like to use your DeathByCaptcha account ?")
        if DBC:
            DBC_Username = raw_input("Enter your DBC Username: "******"Enter your DBC Password: "******"[!] " + e.message

    # Manually pop the cpatcha to be solved
    captchaObj = hashkiller.PopCaptcha

    # Work to be called by the threads
    def ThreadWork(md5, captchaObj, SaveTo, DeathByCaptchaClient):
        while not md5.empty():
            try:
                # Declare HashKiller class and set md5 hashs
示例#17
0
  left = location['x']
  top = location['y']
  right = location['x'] + size['width']
  bottom = location['y'] + size['height']
  im = im.crop((left, top, right, bottom)) # defines crop points
  im.save(filename) # saves new cropped image

timeout = 30
WINDOW_SIZE = "1920,1080"
chrome_options = Options()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE)
driver = webdriver.Chrome(options=chrome_options)
##driver = webdriver.Chrome()
##driver.maximize_window()
dbc_client = deathbycaptcha.SocketClient("anoopmr", "bangal0@rE")
inputs = get_inputs()
count_data = 1
for input_tuples in inputs:
    #print("XXXXXX",input_tuples)
    project_id = int(input_tuples[0])
    year_input = int(input_tuples[1])
    maharastra_input = input_tuples[7]
    district_input = input_tuples[2]
    tahsil_input = input_tuples[3]
    village_input = input_tuples[4]
    property_input = int(input_tuples[5])
    name_input = input_tuples[6]
    print("Processing:", count_data)
    maharastra = False
##    print(year_input, i)
示例#18
0
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
import urllib
import time
import csv
import os
import deathbycaptcha
import base64
import json

url = 'http://www8.receita.fazenda.gov.br//SimplesNacional/Aplicacoes/ATBHE/ConsultaOptantes.app/ConsultarOpcao.aspx'

driver = webdriver.Chrome()
userDBC = input('deathbycaptcha username: '******'deathbycaptcha password: '******'nome': 'none', 'cnpj': 'none', 'situacao': 'none'}


def consulta(empresa, cnpj, index):
    driver.get(url)
    #driver.switch_to.frame('frame')
    #cnpj_field = driver.find_element_by_xpath('//*[@id="ctl00_ContentPlaceHolderConteudo_636506548656840706"]')
    cnpj_field = driver.find_element_by_class_name('caixaTexto')
    time.sleep(3)
    captcha_image = driver.find_element_by_id('img-captcha2')
    img_captcha_base64 = driver.execute_async_script(
        """
        var ele = arguments[0], callback = arguments[1];
示例#19
0
# Get the location automatically
left = element.location_once_scrolled_into_view['x']
top = element.location_once_scrolled_into_view['y']  # +300
right = element.location_once_scrolled_into_view['x'] + size['width']
bottom = element.location_once_scrolled_into_view['y'] + size['height']  # +300
im = im.crop((left, top, right, bottom))  # defines crop points
# im = im.crop((230, 690, 630, 800))  defines crop points
im.save('captcha.png')
'''

# Send the captcha to the DeathByCaptcha
username = "******"
password = "******"

# Send the captcha
client = deathbycaptcha.SocketClient(username, password)
captcha = client.decode("captcha.png", 15)

# Get the solution
solution = captcha["text"]

# Find the text box
web_elem = driver.find_element("name", "codigo_captcha")

# Send the captcha results
web_elem.send_keys(solution)

# Request the data_scraping
button = driver.find_element("name", "submit")

# Click the button
示例#20
0
from selenium import webdriver
from selenium.webdriver.common import keys
import requests 
import time
import deathbycaptcha
print('Amazon Handler')
captcha_client = deathbycaptcha.SocketClient('sanjusvkss', 'Sanjeev@838')

detail_id_dict={
	'ap_customer_name':'Name',
	'ap_email':'Email Address',
	'ap_password':'******',
	'ap_password_check':'Password'
}
driver=''

addr_detail_dict={
	'address-ui-widgets-enterAddressFullName':'Ravi',
	'address-ui-widgets-enterAddressPhoneNumber' : '8987876787',
	'address-ui-widgets-enterAddressPostalCode':'534101',
	'address-ui-widgets-enterAddressLine1':'fgdhfd',
	'address-ui-widgets-enterAddressLine2':'abcdef',
	'address-ui-widgets-enterAddressCity':'Tadepalligudem'
}

def initialise_driver(chromedriver_path):
	global driver
	driver = webdriver.Chrome(chromedriver_path)
	driver.implicitly_wait(15)
	
def open_create_client_page():
示例#21
0
 def _client(self):
     if not self._deathbycaptcha_client:
         self._deathbycaptcha_client = deathbycaptcha.SocketClient(
             self._username, self._password)
     return self._deathbycaptcha_client
示例#22
0
def search_number(application_number):
    agent = requests.session()
    url = 'http://ipindiaonline.gov.in/eregister/Application_View.aspx'
    html = agent.get(url)
    soup = BeautifulSoup(html.content, 'lxml')

    pay = dict()
    for param in soup.find_all('input', {'type': "hidden"}):
        key = param.get('id')
        value = param.get('value')
        pay[key] = value

    pay['__EVENTTARGET'] = 'rdb$0'
    pay['__EVENTARGUMENT'] = ''
    pay['__LASTFOCUS'] = ''
    pay['rdb'] = 'N'

    tt = ''
    for dd in soup.find_all('script'):
        ch = dd.get('src')
        if ch and '/eregister/Application_View.aspx' in ch:
            tt = ch.split('TSM_CombinedScripts_=')[1]
    pay['ToolkitScriptManager1_HiddenField'] = tt
    html = agent.post(
        'http://ipindiaonline.gov.in/eregister/Application_View.aspx',
        data=pay)

    soup = BeautifulSoup(html.content, 'lxml')

    payload = dict()
    for param in soup.find_all('input', {'type': "hidden"}):
        key = param.get('id')
        value = param.get('value')
        payload[key] = value

    tt = ''
    for dd in soup.find_all('script'):
        ch = dd.get('src')
        if ch and '/eregister/Application_View.aspx' in ch:
            tt = ch.split('TSM_CombinedScripts_=')[1]

    captcha_url = 'http://ipindiaonline.gov.in/eregister/captcha.ashx'
    client = deathbycaptcha.SocketClient('KamleshKumar', 'P@ssWind@123')
    img = agent.get(captcha_url)
    captcha_path = 'public/' + uuid.uuid4().hex + '.jpeg'
    h = open(captcha_path, 'wb')
    h.write(img.content)
    h.close()
    captcha = client.decode(captcha_path, 100)
    # Remove Files
    os.remove(captcha_path)
    payload['ToolkitScriptManager1_HiddenField'] = tt
    payload['__EVENTTARGET'] = ''
    payload['__EVENTARGUMENT'] = ''
    payload['btnView'] = 'View+'
    payload['applNumber'] = application_number
    payload['captcha1'] = captcha['text']

    url = 'http://ipindiaonline.gov.in/eregister/Application_View.aspx'
    html = agent.post(url, data=payload).content

    soup = BeautifulSoup(html, 'lxml')
    load = dict()
    for param in soup.find_all('input', {'type': "hidden"}):
        key = param.get('id')
        value = param.get('value')
        load[key] = value

    tt = ''
    for dd in soup.find_all('script'):
        ch = dd.get('src')
        if ch and '/eregister/Application_View.aspx' in ch:
            tt = ch.split('TSM_CombinedScripts_=')[1]

    load['ToolkitScriptManager1_HiddenField'] = tt
    load['__EVENTTARGET'] = 'SearchWMDatagrid$ctl03$lnkbtnappNumber1'
    load['__EVENTARGUMENT'] = ''

    html = agent.post(
        'http://ipindiaonline.gov.in/eregister/Application_View.aspx',
        data=load)
    if html.status_code == 200:
        soup = BeautifulSoup(html.content, 'lxml')
        error = soup.find('span', {'id': "errorText"})
        success = soup.find('span', {'id': "lblappdetail"})
        if error:
            error = error.text.strip()
            return 'Error Not Found'
        elif success and 'NOT FOR LEGAL USE' in success.text:
            file_name = 'public/' + str(hashlib.md5(
                html.content).hexdigest()) + '.html'
            hh = open(file_name, 'wb')
            hh.write(html.content)
            hh.close()
            return file_name
        else:
            return 'Error'
    else:
        return 'Error'
示例#23
0
soup = BeautifulSoup(html.content, 'lxml')

payload = dict()
for param in soup.find_all('input',{'type':"hidden"}):
    key = param.get('id')
    value = param.get('value')
    payload[key] = value

tt = ''
for dd in soup.find_all('script'):
    ch = dd.get('src')
    if ch and '/eregister/Application_View.aspx' in ch:
        tt = ch.split('TSM_CombinedScripts_=')[1]

captcha_url = 'http://ipindiaonline.gov.in/eregister/captcha.ashx'
client = deathbycaptcha.SocketClient('cubictree', 'P@ssw0rd')
img = agent.get(captcha_url)
h = open('captcha.jpeg','wb')
h.write(img.content)
h.close()
captcha = client.decode('captcha.jpeg', 100)
print('captcha {}'.format(captcha))

payload['ToolkitScriptManager1_HiddenField'] = tt
payload['__EVENTTARGET'] = ''
payload['__EVENTARGUMENT'] = ''
payload['btnView'] = 'View+'
payload['applNumber'] = '563412'
payload['captcha1'] = captcha['text']

url = 'http://ipindiaonline.gov.in/eregister/Application_View.aspx'
示例#24
0
def reportCaptcha(captcha):
	usr = "******"
	psw = "######"
	client = deathbycaptcha.SocketClient(usr, psw)
	client.report(captcha)
示例#25
0
def appointment_choice(update, context):
    #read session variable value from context
    session = context.user_data['session']

    #create an  empty appointment dictionary to store hours and locations
    appointments_dictionary = {}
    all_available_dates = context.user_data['all_available_dates']
    query = update.callback_query
    query.answer()

    #query.message.reply_text('yaaay you have found an appointment date')
    query.edit_message_text(
        text='Selected option: {}.\nPlease wait...'.format(query.data))

    #Create an URL based on the endpoint stored in the all_available_dates list
    appointment_endpoint = ''
    for date, endpoint in all_available_dates:
        if query.data == date:
            url_date = 'https://service.berlin.de' + endpoint
            appointment_endpoint = endpoint
    appointment_endpoint = appointment_endpoint.partition(
        "/terminvereinbarung/termin/time/")[2]

    #debug message to see if the url is correct, create a session using this url
    print(url_date)
    r = session.get(url_date)
    #Clear the global variable in case something goes wrong and the user retries
    all_available_dates.clear()

    #See where the bot is, probably stuck on captcha
    captcha_detected = r.url
    print(captcha_detected)
    parseData = BeautifulSoup(r.text, 'html.parser')
    captcha_passed = False
    if captcha_detected == 'https://service.berlin.de/terminvereinbarung/termin/human/':
        while captcha_passed is False:
            print('Captcha verification... please wait')
            captcha_container = parseData.find(
                'form', {'action': '/terminvereinbarung/termin/human/'})
            captcha_image = captcha_container.find('img')
            captcha_image_url = captcha_image['src']

            #The URL looks like this: 'data:image/png;base64,iVBORw0KG...', base64 string is needed to generate the captcha image
            #Using string.partition() you put the string as function argument and then use the index [2] to get the remainder of the string
            #This array has 3 indexes (0,1,2):
            #0 - string that comes before the string from the input (in this case - its an empty string because data:image/png;base64 is the beginning of the string)
            #1 - is the string from the input
            #2 - what comes after the string from the input
            base64_from_url = captcha_image_url.partition(
                "data:image/png;base64,")[2]

            #Generate a random filename using tempfile module
            tf = tempfile.NamedTemporaryFile()
            captcha_filename = tf.name
            print(captcha_filename)

            #Get the binary data, open the file and write to it
            binary_data = a2b_base64(base64_from_url)
            fd = open(captcha_filename, 'wb')
            fd.write(binary_data)

            #Send the image to DeathByCaptcha
            deathbycaptcha_timeout = 30  #30 second timeout for captcha solving, can be adjusted if it is too short
            deathbycaptcha_client = deathbycaptcha.SocketClient(
                deathbycaptcha_username, deathbycaptcha_password)
            try:
                captcha_to_resolve = deathbycaptcha_client.decode(
                    captcha_filename, deathbycaptcha_timeout)
                if captcha_to_resolve:
                    print("CAPTCHA %s solved: %s" %
                          (captcha_to_resolve["captcha"],
                           captcha_to_resolve["text"]))
                    resolved_captcha = captcha_to_resolve["text"]
            except deathbycaptcha.AccessDeniedException:
                print('DeathByCaptcha Access DENIED')

            #The captcha form is a GET form so we need to modify the URL here with the right text
            #Example:
            #https://service.berlin.de/terminvereinbarung/termin/human/?captcha_text=hMddiv
            captcha_getform_url = captcha_detected + '?captcha_text=' + resolved_captcha
            print(captcha_getform_url)
            r = session.get(captcha_getform_url)
            #Debug msg: CHECK CURRENT URL
            print(r.url)
            #For some reason it is redirecting to https://service.berlin.de/terminvereinbarung/termin/time/ and this is
            #not the correct url and the date of the appointment scrapped from this URL is a default date (year 1970)
            #We need to recreate the session with the URL with endpoint, the one just before captcha redirect (variable: url_date)

            #Captcha verification is okay when the current url looks exactly like this. Exit the loop, else it will try to resolve the captcha again
            if r.url == 'https://service.berlin.de/terminvereinbarung/termin/time/':
                captcha_passed = True

            #Debug: See if the date is correct
            r = session.get(url_date)

            parseData = BeautifulSoup(r.text, 'html.parser')
            print(r.url)

    else:
        parseData = BeautifulSoup(r.text, 'html.parser')
        print('NO captcha verification, yaaay!')

    #Get the list of all available hours
    available_hours = parseData.findAll('th', {'class': 'buchbar'})
    #Get the list of all available locations
    available_locations = parseData.findAll('td', {'class': 'frei'})

    hours = []
    locations = []

    #Save all location urls in a seperate list
    location_urls = []

    for h in available_hours:
        hour = h.text.strip()
        hours.append(hour)
    for l in available_locations:
        location = l.text.strip()
        locations.append(location)

    #DEBUG MSGs
    print(hours)
    print(locations)
    print('\n\n\n')

    for i in available_locations:
        url = i.find('a')['href']
        location_urls.append(url)

    print(location_urls)

    #Create a key-value pair of location and location urls
    combined_url_location = []
    location_counter = 0
    for item in locations:
        combined_url_location.append(
            tuple((item, location_urls[location_counter])))
        location_counter += 1

    #DEBUG MSGs
    print('\n\n\n')
    print(combined_url_location)

    #Create a dictionary to store key and values for locations and available hours
    #It is necessary as one hour can hold multiple locations

    hour_cycle = cycle(
        hours)  #Using cycle to get access to next value in a list
    for location in combined_url_location:
        #Get the current value, starting with the 0 index of the hours list
        current_value = next(hour_cycle)
        #If current value is not an empty string (so it is an hour), assign key as a current_value, and the location is the value
        if current_value != '':
            appointments_dictionary[current_value] = [location]
            #Save this key as it is not empty (to write to it again if there are multiple locations for the same hour)
            last_value = current_value
        #If the current value is empty, get the last_value as a key and store the location
        else:
            appointments_dictionary[last_value].append(location)

    #DEBUG msg
    print(appointments_dictionary)

    #Get only hours from the dictionary
    dictionary_hour_list = []
    for key in appointments_dictionary:
        dictionary_hour_list.append(key)
    print(dictionary_hour_list)

    #Create a keyboard with buttons for each hour of the appointment (4 different hours in a row)
    #When user clicks on a specific hour, callback data captures this response
    keyboard = []
    buttons_per_row = 4
    for i, x in enumerate(dictionary_hour_list):
        if i % buttons_per_row == 0:
            keyboard.insert(len(keyboard), [
                InlineKeyboardButton(
                    x, callback_data=(x + ' ' + appointment_endpoint))
            ])
        else:
            keyboard[len(keyboard) - 1].append(
                InlineKeyboardButton(x,
                                     callback_data=(x + ' ' +
                                                    appointment_endpoint)))

    reply_markup = InlineKeyboardMarkup(keyboard)
    query.edit_message_text(text="Please choose the time  of the appointment:",
                            reply_markup=reply_markup)
    context.user_data['appointments_dictionary'] = appointments_dictionary

    return FIRST
password = "******"
# you can use authtoken instead of user/password combination
# activate and get the authtoken from DBC users panel
authtoken = ""

# Put the proxy and reCaptcha token data
Captcha_dict = {
    'proxy': 'http://*****:*****@127.0.0.1:1234',
    'proxytype': 'HTTP',
    'googlekey': '6Lc2fhwTAAAAAGatXTzFYfvlQMI2T7B6ji8UVV_f',
    'pageurl': 'http://google.com'}

# Create a json string
json_Captcha = json.dumps(Captcha_dict)

client = deathbycaptcha.SocketClient(username, password, authtoken)
# to use http client client = deathbycaptcha.HttpClient(username, password)
# client = deathbycaptcha.HttpClient(username, password, authtoken)

try:
    balance = client.get_balance()
    print(balance)

    # Put your CAPTCHA type and Json payload here:
    captcha = client.decode(type=4, token_params=json_Captcha)
    if captcha:
        # The CAPTCHA was solved; captcha["captcha"] item holds its
        # numeric ID, and captcha["text"] item its list of "coordinates".
        print ("CAPTCHA %s solved: %s" % (captcha["captcha"], captcha["text"]))

        if '':  # check if the CAPTCHA was incorrectly solved