Esempio n. 1
0
    def __init__(self):
        # # 配置chrome下载对话框的参数
        # options = webdriver.ChromeOptions()
        # prefs = {'profile.default_content_settings.popups': 0, }
        # options.add_experimental_option('prefs', prefs)
        # # 设置开发者模式,防止被检测
        # options.add_experimental_option('excludeSwitches', ['enable-automation'])
        # # 设置UA代理
        # # options.add_argument('user-agent=%s' % random.choice(proxies))
        # chrome_driver = r'E:\Anaconda\Lib\site-packages\selenium\webdriver\chrome\chromedriver.exe'
        # # options.add_argument('--headless')
        # # 初始化chrome浏览器
        # driver = webdriver.Chrome(chrome_options=options, executable_path=chrome_driver)
        op = Operation()
        driver = op.driver
        driver.get('https://mycaifuhao.eastmoney.com/usercenter')
        # WebDriverWait(driver, 10).until(
        #     EC.presence_of_element_located((By.ID, 'loginForm'))
        # )
        driver.maximize_window()
        time.sleep(5)
        op.switch_frame("//iframe[@name='my_iframe']")
        op.click("//input[@id='txt_account']")
        op.input_text('txt_account', '18317137759')
        op.click("//input[@id='txt_pwd']")
        op.input_text('txt_pwd', '999*htffund')
        time.sleep(1)
        op.click("//button[@id='btn_login']")
        time.sleep(1)
        op.click("//div[@class='em_init_icon']")
        global LOG_COOKIES
        LOG_COOKIES = driver.get_cookies()

        with open(FILE_PATH, 'w', encoding='utf-8') as f:
            f.write('')
            f.close()
Esempio n. 2
0
def run_operation():
    #print('-1')
    op = Operation()
    # print('0')
    driver = op.driver

    #print('1')

    op.quit_frame()
    op.click('//a[text()="平台招商"]')
    time.sleep(2)
    download_tag_1 = '//div[@class="ant-spin-container"]/div/div/button'
    download_tag_2 = '//div[@class="ant-row ant-form-item"]//div[@class="ant-form-item-control"]//button'
    op.roll_down_window(download_tag_1)
    op.delete_file()
    #print("delete finish")

    selector_xpaths = []
    for i in range(1, 4):
        selector_xpath = '//div[@class="ant-modal-root"]/../following-sibling::div[2]//ul[@class="ant-select-dropdown-menu  ant-select-dropdown-menu-root ant-select-dropdown-menu-vertical"]//li[{}]'.format(
            i)
        # selector_xpath = "//div[@style=\"width: 200px; left: 224px; top: 227px;\"]//ul[@class=\"ant-select-dropdown-menu  ant-select-dropdown-menu-root ant-select-dropdown-menu-vertical\"]//li[{}]".format(
        #     i)
        #selector_xpath = "//ul[@class=\"ant-select-dropdown-menu ant-select-dropdown-menu-vertical  ant-select-dropdown-menu-root\"]//li[{}]".format(i)
        selector_xpaths.append(selector_xpath)
    date_xpath = "//ul[@role=\"listbox\"]//li[2]"

    file_class = ['申购一(拉新)', '申购二(满减)', '定投']
    for index, selector_xpath in enumerate(selector_xpaths):
        op.click(download_tag_1)
        # 点击下载类型
        if index == 0:
            pass
        else:
            # time.sleep(1)
            op.click(
                '//label[@title="请选择下载类型"]/../following-sibling::div[1]//div[@class="ant-select-selection__rendered"]'
            )
            # op.click(
            #     '//div[@class="ant-modal-content"]//div[@class="ant-form-item-control has-success"]//div[@class="ant-select-selection__rendered"]')
            # time.sleep(1)
            # driver.find_elements_by_xpath('//ul[@class="ant-select-dropdown-menu  ant-select-dropdown-menu-root ant-select-dropdown-menu-vertical"]')[0].find_elements_by_xpath('//li')[1].click()
            #
            op.click(selector_xpath)
        # time.sleep(1)
        op.click(
            '//label[@title="选择明细报表"]/../following-sibling::div[1]//div[@class="ant-select-selection__rendered"]'
        )
        # op.click(
        #    '//div[@class="ant-modal-content"]//div[@class="ant-form-item-control"]//div[@class="ant-select-selection__rendered"]')
        #op.click(selector_xpaths[1])
        # time.sleep(1)
        op.click(date_xpath)
        # time.sleep(1)
        op.click(download_tag_2)
        time.sleep(2)
        op.file_rename(file_class[index])
    driver.back()
Esempio n. 3
0
def main():
    op = Operation()
    driver = op.driver
    driver.get('https://wshop.alipay.com/op-overview?activeKey=target')
    time.sleep(3)
    driver.switch_to.frame('myreports-target')  # 必须
    date_xpath = "//span[text()='最新数据截止:']/following-sibling::span"
    date = driver.find_element_by_xpath(
        date_xpath).get_attribute('textContent')
    data_list = []

    # 获取第一行 index_list缺少第一个 原因未知 可优化 TODO
    one_line = [date]
    xpath = "//div[@class='ant-select-selection-selected-value']"
    one_line.append(driver.find_element_by_xpath(
        xpath).get_attribute('textContent'))
    try:
        xpath = "//p[text()='最新本机构排名']/following-sibling::div/p/span"
        rank_of_this_institution = driver.find_element_by_xpath(
            xpath).get_attribute('textContent')
    except selenium.common.exceptions.NoSuchElementException:
        rank_of_this_institution = '无'
    one_line.append(rank_of_this_institution)
    # 读取前十
    xpath = "//div[@class='ant-col-12']//span"
    rank_list = driver.find_elements_by_xpath(xpath)  # 当前指标前十列表
    for rank in rank_list:
        one_line.append(rank.get_attribute('textContent'))
    data_list.append(one_line)

    # 点击指标列表
    select_xpath = "//div[@class='ant-select-selection__rendered']"
    op.click(select_xpath)

    xpath = "//li[@class='ant-select-dropdown-menu-item']"
    index_list = driver.find_elements_by_xpath(xpath)  # 指标列表
    length = len(index_list)
    # 关闭指标列表
    select_xpath = "//div[@class='ant-select-selection__rendered']"
    op.click(select_xpath)

    for i in range(length):
        one_line = [date]
        # 再打开指标列表
        op.click(select_xpath)
        index = index_list[i].get_attribute('textContent')
        one_line.append(index)
        index_list[i].click()
        time.sleep(3)
        # 读取本机构排名
        try:
            xpath = "//p[text()='最新本机构排名']/following-sibling::div/p/span"
            rank_of_this_institution = driver.find_element_by_xpath(
                xpath).get_attribute('textContent')
        except selenium.common.exceptions.NoSuchElementException:
            rank_of_this_institution = '无'
        one_line.append(rank_of_this_institution)
        # 读取前十
        xpath = "//div[@class='ant-col-12']//span"
        rank_list = driver.find_elements_by_xpath(xpath)  # 当前指标前十列表 2-10
        for rank in rank_list:
            one_line.append(rank.get_attribute('textContent'))
        data_list.append(one_line)

    headers = ['date', 'index', 'rank']
    for i in range(1, 11):
        headers.append('rank_{}'.format(i))

    with open('data/institution_rank.csv', 'w', encoding='gbk', newline='') as fp:  # utf-8编码会有乱码
        writer = csv.writer(fp)
        # writer.writerow(headers)
        writer.writerows(data_list)
        fp.close()
    time.sleep(2)
    driver.get('https://wshop.alipay.com/home')
    time.sleep(3)
Esempio n. 4
0
# rank_time = time.strftime('%Y%m%d', time.localtime(time.time()-24*60*60))
op = Operation()
driver = op.driver
url = 'https://wshop.alipay.com/'

USERNAME = '******'
PASSWD = 'htf99!123'

while True:
    try:
        driver.get(url)
        driver.implicitly_wait(3)
        driver.maximize_window()

        op.click(XPATH['homepage']['login_xpath'])
    except:
        time.sleep(2)
        # driver.quit()
    else:
        break

time.sleep(3)

op.click(XPATH['homepage']['login_way_xpath'])

op.click_id(ID_XPATH['login']['acc_xpath'])
op.input_text(ID_XPATH['login']['acc_xpath'], USERNAME)

op.click_id(ID_XPATH['login']['pwd_xpath'])
op.input_text(ID_XPATH['login']['pwd_xpath'], PASSWD)
Esempio n. 5
0
# rank_time = time.strftime('%Y%m%d', time.localtime(time.time()-24*60*60))
op = Operation()
driver = op.driver
url = 'https://wshop.alipay.com/'

USERNAME = '******'
PASSWD = 'htfzfb!123'

while True:
    try:
        driver.get(url)
        driver.implicitly_wait(3)
        driver.maximize_window()

        op.click(XPATH['homepage']['login_xpath'])
    except:
        time.sleep(2)
        # driver.quit()
    else:
        break

time.sleep(3)

op.click(XPATH['homepage']['login_way_xpath'])

op.click_id(ID_XPATH['login']['acc_xpath'])
op.input_text(ID_XPATH['login']['acc_xpath'], USERNAME)

op.click_id(ID_XPATH['login']['pwd_xpath'])
op.input_text(ID_XPATH['login']['pwd_xpath'], PASSWD)