Beispiel #1
0
def auto_work(user, paras, url):
    print('-' * 50)
    print(time.strftime('%y-%m-%d %H:%M:%S', time.localtime(time.time())))
    print('当前处理账户名为:{}'.format(user))
    driver = webdriver.Chrome()
    driver.get(url)
    time.sleep(2)
    result = choose_bank(driver, paras['location'], paras['cointype'])
    if result != False:
        find_and_fill(driver, '//*[@id="txtName"]', user)
        find_and_fill(driver, '//*[@id="txtPpNum"]', paras['identNo'])
        find_and_fill(driver, '//*[@id="txtTel"]', paras['mobile'])
        find_and_click(driver, '//*[@id="nextstep3"]')
        handle_coindate(driver)
        handle_capchar(driver)
        appoint_cnt = driver.find_element_by_xpath(
            '//*[@id="nums"]').get_attribute('value')
        max_cnt = driver.find_element_by_xpath(
            '//*[@id="perbooknum"]').text.split('-')[-1][:-1]
        while True:
            find_and_click(driver, '//*[@id="js_submit"]')
            time.sleep(1)
            if appoint_cnt != max_cnt:
                try:
                    driver.switch_to.alert.accept()
                    time.sleep(3)
                    break
                except:
                    continue
        print('预约成功!')
    else:
        print('该营业处已约完!')
Beispiel #2
0
def get_mobile_code(driver, mobile, model, lb):
    handle_capchar(driver, model, lb)
    ele_mobile = driver.find_element_by_xpath('//*[@id="mobile"]')
    ele_mobile.send_keys(mobile)
    while True:
        find_and_click(driver, '//*[@id="sendValidate"]')
        ele_errorCaptchaNo = driver.find_element_by_xpath(
            '//*[@id="errorCaptchaNo"]')
        if ele_errorCaptchaNo.text == '短信验证码已发送成功':
            break
        else:
            find_and_click(driver, '//*[@id="piccaptcha"]')
            time.sleep(0.1)
            handle_capchar(driver, model, lb)
Beispiel #3
0
def auto_work(user, paras, model, lb, url):
    print('-' * 50)
    print(time.strftime('%y-%m-%d %H:%M:%S', time.localtime(time.time())))
    print('当前处理账户名为:{}'.format(user))
    driver = webdriver.Chrome()
    driver.get(url)
    get_mobile_code(driver, paras['mobile'], model, lb)
    find_and_fill(driver, '//*[@id="name"]', user)
    find_and_fill(driver, '//*[@id="identNo"]', paras['identNo'])
    find_and_fill(driver, '//*[@id="cardvalue0"]', paras['cardvalue0'])
    choose_bank(driver, paras['location'])
    handle_coindate(driver)
    phoneCaptchaNo = input('请输入手机验证码, 按回车键确认(如果还未收到短信,请等到短信之后再输入):\n')
    find_and_fill(driver, '//*[@id="phoneCaptchaNo"]', phoneCaptchaNo)
    find_and_click(driver, '//*[@id="infosubmit"]')
    time.sleep(2)
Beispiel #4
0
def handle_coindate(driver):
    is_find = False
    find_and_click(driver, '//*[@id="coindate"]')
    while not is_find:
        for tr_index in range(6):
            for td_index in range(7):
                try:
                    ele_td = driver.find_element_by_xpath(
                        '//*[@id="ui-datepicker-div"]/table/tbody/tr[{}]/td[{}]'
                        .format(str(tr_index + 1), str(td_index + 1)))
                except:
                    continue
                if ele_td.get_attribute('title') == '可选择':
                    is_find = True
                    ele_td.click()
                    return
        find_and_click(driver, '//*[@id="ui-datepicker-div"]/div/a[2]/span')
Beispiel #5
0
def choose_bank(driver, location, cointype):
    locations = location.split(',')
    for province_index in range(15):
        ele_province = driver.find_element_by_xpath(
            '//*[@id="areainfo"]/input[{}]'.format(str(province_index + 1)))
        if locations[0] in ele_province.get_attribute('value'):
            if '已约完' in ele_province.text:
                return False
            else:
                ele_province.click()
                break
    bank_xpath = [
        # ('//*[@id="selcoinType"]', cointype),
        ('//*[@id="selonebank"]', locations[0] if len(locations) > 0 else '分行'
         ),
        ('//*[@id="seltwobank"]',
         locations[1] if len(locations) > 1 else '分行'),
        ('//*[@id="selbank"]', locations[2] if len(locations) > 2 else '支行'),
    ]
    # element = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath('//*[@id="selcoinType"]'))
    for xpath, filter in bank_xpath:
        while True:
            try:
                ele_target = driver.find_element_by_xpath(xpath)
                break
            except:
                continue
        for option_index, option in enumerate(ele_target.text.split('\n')[1:]):
            if filter in option:
                find_and_click(
                    driver,
                    xpath + '/option[{}]'.format(str(option_index + 1)))
                break
    find_and_click(driver, '//*[@id="nextstep1"]')
    try:
        ele_result = driver.find_element_by_xpath('//*[@id="timeerrordiv"]')
        if '该网点额度已被抢光' in ele_result.text:
            return False
        else:
            return True
    except:
        return True
Beispiel #6
0
def choose_bank(driver, location):
    top_xpath = '//*[@id="orglevel1"]'
    locations = location.split(',')
    for index, loca in enumerate(locations):
        level = str(index + 1)
        xpath = top_xpath.replace('1', level)
        ele_orglevel = driver.find_element_by_xpath(xpath)
        for org_index, org in enumerate(ele_orglevel.text.split('\n')):
            if loca in org:
                find_and_click(
                    driver, xpath + '/option[{}]'.format(str(org_index + 1)))
                break
    xpath = top_xpath.replace('1', str(len(locations) + 1))
    try:
        ele_bottom = driver.find_element_by_xpath(xpath)
    except:
        return
    else:
        org_index = random.choice(
            list(range(len(ele_bottom.text.split('\n'))))[1:])
        find_and_click(driver,
                       xpath + '/option[{}]'.format(str(org_index + 1)))