Beispiel #1
0
def get_raw_captcha(url, n, outdir=os.curdir, session=None):
    for i in range(n):
        captcha_name = add_postfix('captcha', str(i))
        get_image(url,
                  captcha_name=captcha_name,
                  outdir=outdir,
                  session=session)
Beispiel #2
0
def get_image_test():
    from minghu6.graphic.captcha.get_image import get_image
    session = requests.Session()

    imgObj = get_image('http://zyzfw.xidian.edu.cn/site/captcha?v=5832eb2835057', session=session)[0]
    imgObj.show()

    imgObj = get_image('http://zyzfw.xidian.edu.cn/site/captcha?v=5832eb2835057', session=session)[0]
    imgObj.show()
Beispiel #3
0
def get_image_test():
    from minghu6.graphic.captcha.get_image import get_image
    session = requests.Session()

    imgObj = get_image(
        'http://zyzfw.xidian.edu.cn/site/captcha?v=5832eb2835057',
        session=session)[0]
    imgObj.show()

    imgObj = get_image(
        'http://zyzfw.xidian.edu.cn/site/captcha?v=5832eb2835057',
        session=session)[0]
    imgObj.show()
Beispiel #4
0
def main_split(path, num=None, split_method='bisect', outdir=os.path.curdir):
    # path, n=None, split_method='bisect', outdir=os.path.curdir

    assert split_method in split_method_dict, 'split_method do not exist!'

    assert num is not None or split_method != 'bisect', 'bisect method need the param n'
    split_method = split_method_dict[split_method]

    imgObj, image_path = get_image(path)
    box_img = split_method(imgObj, n=num)

    # base_path = os.path.join(outdir, os.path.basename(path))
    for i, sub_img in enumerate(box_img):
        sub_img_path = add_postfix(image_path, '{0:d}'.format(i))
        sub_img.save(sub_img_path)
Beispiel #5
0
def main_split(path, num=None, split_method='bisect', outdir=os.path.curdir):
    # path, n=None, split_method='bisect', outdir=os.path.curdir

    assert split_method in split_method_dict, 'split_method do not exist!'

    assert num is not None or split_method != 'bisect', 'bisect method need the param n'
    split_method = split_method_dict[split_method]

    imgObj, image_path = get_image(path)
    box_img = split_method(imgObj, n=num)

    # base_path = os.path.join(outdir, os.path.basename(path))
    for i, sub_img in enumerate(box_img):
        sub_img_path = add_postfix(image_path, '{0:d}'.format(i))
        sub_img.save(sub_img_path)
def pythonscraping__com_humans_only_test():
    from minghu6.internet.simulate_logon import pythonscraping__com_humans_only as logon
    from minghu6.graphic.captcha.url_captcha import pythonscraping__com_humans_only as get
    from minghu6.graphic.captcha.get_image import get_image

    responseSet = get()

    captchaUrl, session = responseSet[:2]
    params_dict = responseSet[-1]

    imgObj, _ = get_image(captchaUrl)
    imgObj.show()
    captcha = input('input captcha please\n').strip()
    params_dict['captcha_response'] = captcha
    logon(session=session, **params_dict)
    print(params_dict)
def pythonscraping__com_humans_only_test():
    from minghu6.internet.simulate_logon import pythonscraping__com_humans_only as logon
    from minghu6.graphic.captcha.url_captcha import pythonscraping__com_humans_only as get
    from minghu6.graphic.captcha.get_image import get_image

    responseSet = get()

    captchaUrl, session = responseSet[:2]
    params_dict = responseSet[-1]

    imgObj, _ = get_image(captchaUrl)
    imgObj.show()
    captcha = input('input captcha please\n').strip()
    params_dict['captcha_response'] = captcha
    logon(session=session, **params_dict)
    print(params_dict)
Beispiel #8
0
def main_preprocessing(path, preprocessing_method, outdir=os.path.curdir, width=None):
    imgObj, image_path = get_image(path)

    # from list to set

    assert preprocessing_method in preprocessing_method_dict.keys(), 'invalid params in -prepro'
    other_kwargs = {}
    if preprocessing_method == 'remove_frame' and width is not None:
        other_kwargs['frame_width'] = int(width)

    try:
        imgObj = preprocessing_method_dict[preprocessing_method](imgObj, **other_kwargs)
        # imgObj.show()
    except pp.ImageSizeError as ex:
        print(ex)

    newpath = add_postfix(image_path, PREPROCESSING_FLAG_DICT[preprocessing_method])
    imgObj.save(newpath)
Beispiel #9
0
def tesseract(path, limit_config=None, args=None, session: requests = None):
    if not has_proper_tesseract():
        raise DoNotHaveProperVersion

    imgObj, image_path = get_image(path, session=session)

    if args is None:
        cmd_str = 'tesseract -psm 8 {0} stdout '.format(image_path)
    else:
        cmd_str = ' '.join(['tesseract', args, image_path, 'stdout'])
        print(cmd_str)

    if limit_config is not None:  # like digits
        cmd_str += ' {0}'.format(limit_config)

    info_lines, err_lines = exec_cmd(cmd_str, shell=True)

    try:
        captchaResponse = info_lines[0].strip()
    except IndexError:
        raise Exception(''.join(err_lines))
    else:
        return captchaResponse
Beispiel #10
0
def main_preprocessing(path,
                       preprocessing_method,
                       outdir=os.path.curdir,
                       width=None):
    imgObj, image_path = get_image(path)

    # from list to set

    assert preprocessing_method in preprocessing_method_dict.keys(
    ), 'invalid params in -prepro'
    other_kwargs = {}
    if preprocessing_method == 'remove_frame' and width is not None:
        other_kwargs['frame_width'] = int(width)

    try:
        imgObj = preprocessing_method_dict[preprocessing_method](
            imgObj, **other_kwargs)
        # imgObj.show()
    except pp.ImageSizeError as ex:
        print(ex)

    newpath = add_postfix(image_path,
                          PREPROCESSING_FLAG_DICT[preprocessing_method])
    imgObj.save(newpath)