Beispiel #1
0
def get_user_bill(browser, phone_num, task_id):
    js = 'window.open("https://shop.10086.cn/i/v1/fee/billinfo/{}?_={}");'.format(
        phone_num, (int(time.time() * 1000)))
    browser.execute_script(js)
    time.sleep(1)
    bill = switch_window(browser)
    file = str(task_id) + '\\' + 'bill.html'
    file_name = os.path.join(filedir, file)
    save_source(file_name, bill)
Beispiel #2
0
def get_user_count(browser, phone_num, task_id):
    dt = get_time()
    js = 'window.open("https://shop.10086.cn/i/v1/cust/his/{}?startTime={}&endTime={}&_={}");'.format(
        phone_num, dt[0], dt[1], (int(time.time() * 1000)))
    browser.execute_script(js)
    time.sleep(1)
    count = switch_window(browser)
    file = str(task_id) + '\\' + 'count.html'
    file_name = os.path.join(filedir, file)
    save_source(file_name, count)
Beispiel #3
0
def login_user_cap(browser, phone_num, task_id):
    url = 'https://login.10086.cn/login.html'
    browser.get(url=url)
    browser.maximize_window()  # 窗口最大化
    WebDriverWait(browser, 3).until(
        EC.presence_of_element_located((By.ID, "sms_login_1")))
    sms_login_1 = browser.find_element_by_id('sms_login_1')
    sms_login_1.click()
    WebDriverWait(browser,
                  3).until(EC.presence_of_element_located((By.ID, "sms_name")))
    sms_name = browser.find_element_by_id('sms_name')
    sms_name.send_keys(phone_num)
    getSMSPwd1 = browser.find_element_by_id('getSMSPwd1')
    getSMSPwd1.click()
    smsphone_err = browser.find_element_by_id('smsphone_err')
    data = get_info(task_id)
    if smsphone_err.is_displayed():
        log.crawler.info('手机号有误')
        data['status_code'] = 1002
        data_to_redis(task_id, data)
        browser.quit()
    WebDriverWait(browser,
                  3).until(EC.presence_of_element_located(
                      (By.ID, "sms_pwd_l")))
    sms_pwd_l = browser.find_element_by_id('sms_pwd_l')
    data['status_code'] = 2003
    data_to_redis(task_id, data)
    smspwd = get_smspwd(task_id)
    sms_pwd_l.send_keys(smspwd)  # 输入手机验证码
    submit_bt = browser.find_element_by_id('submit_bt')
    smspwd_err = browser.find_element_by_id('smspwd_err')
    submit_bt.click()
    time.sleep(0.2)
    if smspwd_err.is_displayed():
        log.crawler.info('请输入正确短信随机码')
        data['status_code'] = 2006
        data_to_redis(task_id, data)
    time.sleep(2)
    log.crawler.info('登陆成功')
    data['status_code'] = 1004
    data['smspwd'] = ''
    data_to_redis(task_id, data)
    time.sleep(1)
    source = browser.page_source
    file = str(task_id) + '\\' + 'home.html'
    file_name = os.path.join(filedir, file)
    save_source(file_name, source)
Beispiel #4
0
def get_user_info(browser, phone_num, task_id):
    js = 'window.open("https://shop.10086.cn/i/v1/cust/info/{}?_={}");'.format(
        phone_num, (int(time.time() * 1000)))
    browser.execute_script(js)
    time.sleep(1)
    info1 = switch_window(browser)
    file1 = str(task_id) + '\\' + 'info1.html'
    file_name = os.path.join(filedir, file1)
    save_source(file_name, info1)
    js = 'window.open("https://shop.10086.cn/i/v1/busi/plan/{}?_={}");'.format(
        phone_num, (int(time.time() * 1000)))
    browser.execute_script(js)
    time.sleep(1)
    info2 = switch_window(browser)
    file2 = str(task_id) + '\\' + 'info2.html'
    file_name = os.path.join(filedir, file2)
    save_source(file_name, info2)
Beispiel #5
0
def get_plan_amt(browser, task_id):
    for i in [1, 2, 4]:
        title = browser.find_elements_by_xpath(
            '//*[@id="switch-data"]/li[{}]/p'.format(i))[0]
        yan(browser, task_id, title)
        for j in range(1, 7):
            a = 'month' + str(j)
            month = browser.find_elements_by_xpath(
                '//*[@id="{}"]'.format(a))[0]
            yan(browser, task_id, month)
            data = get_info(task_id)
            data['status_code'] = 3000
            data_to_redis(task_id, data)
            time.sleep(1)
            source = browser.page_source
            title_list = ['套餐及固定费', '通话详单', '上网详单', '短信详单']
            file = str(task_id) + '\\' + title_list[i - 1] + a + '_1' + '.html'
            file_name = os.path.join(filedir, file)
            save_source(file_name, source)
            b = browser.find_elements_by_xpath('//*[@id="notes1"]')
            if b:
                c = b[0].text
                # a = '第1/1页'
                pages = c.split('/')[1].split('页')[0]
                if int(pages) > 1:
                    for k in range(2, int(pages) + 1):
                        time.sleep(1)
                        next = browser.find_element_by_class_name('next')
                        yan(browser, task_id, next)
                        data = get_info(task_id)
                        data['status_code'] = 3000
                        data_to_redis(task_id, data)
                        time.sleep(1)
                        source = browser.page_source
                        file = str(task_id) + '\\' + title_list[
                            i - 1] + a + '_' + str(k) + '.html'
                        file_name = os.path.join(filedir, file)
                        save_source(file_name, source)
                else:
                    pass
            else:
                pass