Exemple #1
0
def login(driver, conf):
    print('Prepare to login@', driver.current_url)
    user_info = conf.get_user_info()
    js = '''
        document.getElementsByClassName('ajaxlink')[0].click();
    '''
    driver.execute_script(js)
    time.sleep(3)
    name_elem = driver.find_element_by_id('username')
    name_elem.clear()
    name_elem.send_keys(user_info['username'])
    pw_elem = driver.find_element_by_id('password')
    pw_elem.clear()
    pw_elem.send_keys(user_info['password'])
    captch_dir = '%smf.png' % conf.get_screen_path()
    driver.get_screenshot_as_file(captch_dir)
    print('URL to login for vcode\nhttp://%s/pj/gy/mf178/login_vcode.html' %
          common.get_host_ip())
    vcode = input('Please input vcode from %s\n' % captch_dir)
    vcode_elem = driver.find_element_by_id('vcode')
    vcode_elem.clear()
    vcode_elem.send_keys(vcode)
    driver.find_element_by_id('bt_login').click()
    time.sleep(2)
    print('After login, we are @', driver.current_url)
Exemple #2
0
def web_login(driver, user_info, screen_path):
    print('We are preparing JD web login')
    driver.get('https://order.jd.com/center/list.action')
    time.sleep(4)
    cnt = 0
    success = True
    while driver.current_url.startswith('https://passport.jd.com/uc/login'):
        if cnt > 2:
            break
        cnt += 1
        print('BeforeLogin#', cnt)
        time.sleep(1)
    if driver.current_url.startswith('https://passport.jd.com/uc/login'):
        success = False
        driver.execute_script('$(".login-form").css("float", "left")')
        driver.find_element_by_class_name('login-tab-l').click()
        time.sleep(2)
        web_qr_file = '%sweb_login_qr.png' % screen_path
        driver.get_screenshot_as_file(web_qr_file)
        while driver.current_url.startswith(
                'https://passport.jd.com/uc/login'):
            print(
                'scan QR to login user:%s from URL\thttp://%s/pj/gy/jd/web_qr.html'
                % (user_info['username'], common.get_host_ip()))
            time.sleep(4)
        success = True
    driver.get_screenshot_as_file('%safterWebLogin.png' % screen_path)
    print('After web login url, we are at', driver.current_url)
    time.sleep(2)
    return success
Exemple #3
0
def make_order(driver, product_url, face_value, discount, screen_path):
    count = 0
    succ = False
    current_price = 10000
    while count < 10:
        count = count + 1
        driver.refresh()
        confirm_page_url = driver.current_url
        onsubmit_text = None
        try:
            current_price = float(
                driver.execute_script('''
                var price = document.getElementsByClassName('col3')[1].innerText;
                console.info(price);
                return price;
                '''))
            print('PRICE[%.2f], discount[%.2f]' % (current_price, discount))
            if current_price > face_value * discount:
                continue
            print('#%d--Time to click confirm[%s]' %
                  (count,
                   datetime.datetime.now().strftime('%Y%m%d %H:%M:%S.%f')))
            if onsubmit_text is None or onsubmit_text != '提交中...':
                onsubmit_text = driver.execute_script('''
                    console.info('before click confirm@' + new Date().toLocaleString());
                    document.getElementsByClassName('z-submitbtn')[0].click();
                    console.info(document.getElementsByClassName('z-submitbtn')[0].innerText);
                    console.info('after click confirm@' + new Date().toLocaleString());
                    return document.getElementsByClassName('z-submitbtn')[0].innerText;
                     ''')
            print('%d--Time after click confirm[%s]' %
                  (count,
                   datetime.datetime.now().strftime('%Y%m%d %H:%M:%S.%f')))
            driver.get_screenshot_as_file('%skl_order%d.png' %
                                          (screen_path, count))
            if driver.current_url != confirm_page_url:
                break
        except:
            print('#d-confirm order fail' % count)
            continue
        driver.maximize_window()
        result_shot = '%skl_order.png' % screen_path
        driver.get_screenshot_as_file(result_shot)
        print(
            'URL to see make order result \nhttp://%s/pj/gy/netease/order_result.html'
            % common.get_host_ip())
        time.sleep(10)
        if driver.current_url != confirm_page_url:
            succ = True
        break
    print('We loop %d time(s)' % count)
    if succ:
        print('Success to make order')
    else:
        print('Unable to make order')
    return succ
Exemple #4
0
def make_order2(driver, product_url, face_value, discount, screen_path):
    count = 0
    succ = False
    driver.get(product_url)
    print('Time at click buyBtn[%s]' %
          (datetime.datetime.now().strftime('%Y%m%d %H:%M:%S.%f')))
    driver.execute_script(
        '''
            document.getElementsByName('goods[0].tempBuyAmount')[1].value = arguments[0];
            document.getElementsByName('goods[0].tempBuyAmount')[0].value = arguments[0];
            document.getElementById('buyBtn').click();''', 2)
    while driver.current_url == product_url:
        continue
    while count < 20:
        count = count + 1
        confirm_page_url = driver.current_url
        try:
            price = float(
                driver.execute_script('''
            return document.getElementsByClassName('col3')[1].innerText;
            '''))
            print('PRICE[%.2f], discount[%.2f]' % (price, discount))
            if price > face_value * discount:
                driver.refresh()
                continue
        except:
            driver.refresh()
            continue
        print('Time to click confirm[%s]' %
              (datetime.datetime.now().strftime('%Y%m%d %H:%M:%S.%f')))
        driver.execute_script('''
                    console.info('before click confirm@' + new Date().toLocaleString());
                    document.getElementsByClassName('z-submitbtn')[0].click();
                    console.info('after click confirm@' + new Date().toLocaleString());
                    ''')
        print('Time after click confirm[%s]' %
              (datetime.datetime.now().strftime('%Y%m%d %H:%M:%S.%f')))
        driver.maximize_window()
        result_shot = '%skl_order.png' % screen_path
        driver.get_screenshot_as_file(result_shot)
        print(
            'URL to see make order result \nhttp://%s/pj/gy/netease/order_result.html'
            % common.get_host_ip())
        time.sleep(5)
        if driver.current_url != confirm_page_url:
            succ = True
        break
    print('We loop %d time(s)' % count)
    if succ:
        print('Success to make order')
    else:
        print('Unable to make order')
    return succ
Exemple #5
0
def pay_order(driver, order_info, safe_amount, pay_password, screen_path):
    for x in range(0, 10):
        print('refresh #', x)
        #driver.refresh()
        driver.execute_script('location.reload();')
        pay_ready = 0
        while True:
            pay_ready += 1
            text_pay_amount = driver.execute_script(
                'return $(".pay-next").text();')
            search_result = re.compile('\d+.\d{2}').search(text_pay_amount)
            if search_result is not None:
                amount_to_pay = search_result.group()
                print('Find amount to pay %s with loop #%d' %
                      (amount_to_pay, pay_ready))
                break
        if order_info['order_amount'] - float(amount_to_pay) >= safe_amount:
            print(
                'We arrive safe zone, order amount %.2f, actually pay: %.2f' %
                (order_info['order_amount'], float(amount_to_pay)))
            driver.execute_script('$(".confirm-pay").trigger("touchend");')
            pswd_ready = 0
            need_password = True
            while True:
                pswd_ready += 1
                if ready_to_inputpw(driver) is None:
                    if pswd_ready > 200:
                        need_password = False
                        break
                    continue
                temp = driver.find_element_by_class_name('remark').text
                result = re.compile('\d+.\d{2}').search(temp)
                if result is not None:
                    print('Password input ready with loop #', pswd_ready)
                    break
            if need_password:
                print('feeding pay password')
                for ps in pay_password:
                    dk = 'div[data-key="%d"]' % ps
                    driver.find_element_by_css_selector(dk).click()
            captch_dir = '%sjd_pay.png' % screen_path
            time.sleep(2)
            driver.get_screenshot_as_file(captch_dir)
            print(
                'URL to see pay result \nhttp://%s/pj/gy/jd/web_pay_result.html'
                % common.get_host_ip())
            print('We sleep a while before to end!')
            time.sleep(10)
            return True
    print('Uable to arrive safe zone')
    return False
Exemple #6
0
def click_to_get(driver):
    command = list()
    command.append('$(".coupon").eq(1).click()')
    command.append('$(".coupon").eq(0).click()')
    command.append('$(".coupon").eq(2).click()')
    time.sleep(2)
    print('Click to get coupon@%s' % datetime.datetime.now().strftime('%Y%m%d %H:%M:%S.%f'))
    cnt = 0
    for cmd in command:
        driver.execute_script(cmd)
        driver.execute_script("window.scrollTo(0, 0)")
        driver.execute_script("window.scrollTo(0, 600)")
        path = '%sjd_coupon%d.png' % (conf.get_screen_path(), cnt)
        driver.get_screenshot_as_file(path)
        cnt = cnt + 1
        time.sleep(2)
        print(cmd)
        driver.refresh()
    shot_path = '%sjd_coupon.png' % conf.get_screen_path()
    driver.get_screenshot_as_file(shot_path)
    print(shot_path)
    print('URL for clicking to get coupon PNG\nhttp://%s/pj/gy/jd/coupon_png.html' % common.get_host_ip())
    time.sleep(5)
Exemple #7
0
def jd_login(driver, userInfo, conf):
    print('We are preparing to login')
    cnt = 0
    login_url = 'https://plogin.m.jd.com/login/login'
    while driver.current_url.startswith(login_url):
        if cnt > 2:
            break
        cnt += 1
        print('BeforeLogin#', cnt)
        time.sleep(1)
    if driver.current_url.startswith(login_url):
        elem = driver.find_elements_by_class_name('planBLogin')
        if len(elem) > 0 and elem[0].text != '短信验证码登录':
            print(elem[0].text)
            elem[0].click()
            time.sleep(2)
            print(elem[0].text)
        driver.get_screenshot_as_file('%sbefore.png' % conf.get_screen_path())
        time.sleep(2)
        driver.find_element_by_id('username').send_keys(userInfo['username'])
        time.sleep(1)
        driver.find_element_by_id('pwd').send_keys(userInfo['password'])
        time.sleep(2)
        driver.find_element_by_class_name('btn-active').click()
        time.sleep(5)
    try:
        captcha = driver.find_element_by_id('captcha_modal')
        cap_file = '%scaptcha.png' % conf.get_screen_path()
        driver.get_screenshot_as_file(cap_file)
        print(cap_file)
        code = driver.find_element_by_id('captcha_modal')
        left = int(code.location['x'])
        top = int(code.location['y'])
        right = int(code.location['x'] + code.size['width'])
        bottom = int(code.location['y'] + code.size['height'])
        img = Image.open(cap_file)
        img = img.crop((left, top, right, bottom))
        img.save('%scaptcha2.png' % (conf.get_screen_path()))
        print(
            'URL to login for (x,y) coordinate\nhttp://%s/pj/gy/jd/mouse_pos.html'
            % common.get_host_ip())
        code = get_verfiy_code()
        ActionChains(driver).move_to_element_with_offset(
            captcha, code.get('x'), code.get('y')).click().perform()
        time.sleep(5)
    except:
        print('not verify code')
    if driver.current_url.startswith('https://plogin.m.jd.com/cgi-bin/ml/risk') or\
            driver.current_url.startswith('https://plogin.m.jd.com/h5/risk'):
        print('RiskUri:', driver.current_url)
        print(driver.page_source)
        #driver.execute_script('$(".mode-btn.voice-mode").click();')
        driver.find_element_by_class_name('mode-btn').click()
        time.sleep(3)
    if driver.current_url.startswith('https://plogin.m.jd.com/h5/risk'):
        print('SmsUri:', driver.current_url)
        print(driver.page_source)
        driver.find_element_by_class_name('getMsg-btn').click()
        sms = get_sms_code()
        print(sms)
        driver.find_element_by_class_name('msgCode').send_keys(sms)
        time.sleep(1)
        driver.find_element_by_class_name('btn').click()
        time.sleep(2)
    driver.get_screenshot_as_file('%safterLogin.png' % conf.get_screen_path())
    print('AfterLoginUrl@', driver.current_url)
Exemple #8
0
def get_wechat_pay_qr(driver, order_id, screen_path):
    driver.get('http://chongzhi.jd.com/order/order_pay.action?orderId=%s' % order_id)
    driver.execute_script('$("#weixin").click()')
    time.sleep(2)
    web_qr_file = '%swcp_qr.png' % screen_path
    driver.get_screenshot_as_file(web_qr_file)
    print('OrderID:%s wechat QR pay address from:\thttp://%s/pj/gy/jd/wcp_qr.html' % (order_id, common.get_host_ip()))
    command = input('please input command: q for exit, n for next, f for fresh QR')
    if command == "f":
        return get_wechat_pay_qr(driver, order_id, screen_path)
    return command