• 考试宝导出文件


    import webbrowser
    import time
    
    from selenium.common.exceptions import NoSuchElementException
    from selenium.webdriver.chrome.options import Options
    from selenium import webdriver
    from selenium.webdriver.common.by import By
    import os
    import subprocess
    import re
    # chrome_proxy.exe
    
    def replace_letter(text, replace_letter):
        pattern = re.compile(r'\b{}\b'.format(replace_letter))
        return pattern.sub(replace_letter, text)
    
    # 先切换到chrome可执行文件的路径
    os.chdir(r"C:\\Program Files (x86)\\Google\\Chrome\\Application")
    # # user-data-dir为路径
    subprocess.Popen('chrome.exe --remote-debugging-port=9527 --user-data-dir="D:\project\kaoshibao\AutomationProfile"')
    chrome_options = Options()
    chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9527")
    driver = webdriver.Chrome(options=chrome_options)
    
    
    
    driver.get(
        'https://www.kaoshibao.com/login/?source=https%3A%2F%2Fwww.kaoshibao.com%2Fsctk%2F') # 考试宝地址
    
    input('输入空格继续程序...')
    #要根据自己的题库进行修改的
    driver.get(
        'https://www.kaoshibao.com/online/?paperId=8528245&practice=&modal=1&is_recite=&qtype=&text=%E9%A1%BA%E5%BA%8F%E7%BB%83%E4%B9%A0&sequence=226&is_collect=1&is_vip_paper=0') # 题库地址
    input('输入空格继续程序...')
    driver.implicitly_wait(1)
    
    
    for i in range(900):
        i=i+226
        time.sleep(1)
        all = []
        print("第"+str(i+1)+"次")
        title = driver.find_element_by_xpath("//div[@class='qusetion-box']").text
        try :
            analysis = driver.find_element_by_xpath("//p[@class='answer-analysis']").text
        except NoSuchElementException:
            analysis='无'
        answer = driver.find_element_by_xpath("//div[@class='right-ans']//span").text
        part = driver.find_element_by_xpath("//div[@class='select-left pull-left options-w']").text.replace("\n", ".")
        part = part.replace('.B.', '\nB.', 1)
        part = part.replace('.C.', '\nC.', 1)
        part = part.replace('.D.', '\nD.', 1)
        part = part.replace('.E.', '\nE.', 1)
        part = part.replace('.F.', '\nF.', 1)
    
        # 对内容个性化处理
        title = str(i + 1) + "." + title
        answer = "答案:" + answer
        analysis = "解析:" + analysis
        all.append(title)
        all.append(part)
        all.append(answer)
        all.append(analysis)
        ques = title + ' \n' + part + '\n' + answer + ' \n' + analysis + '\n '
        print("ques"+ques)
        with open(r"D:\\project\\kaoshibao\\2.txt", "a",encoding='utf-8') as f:
            f.write(ques)  # 自带文件关闭功能,不需要再写f.close()
        # 第1条数据 最大化窗口
        if i == 0:
            driver.maximize_window()
            time.sleep(1)
        # 点击下一条
        # driver.find_element(By.CLASS_NAME, 'el-button el-button--primary el-button--small').click()
        driver.find_element_by_xpath('//button[@class="el-button el-button--primary el-button--small"]').click()
        time.sleep(3)
    
    
    
    # 退出浏览器
    driver.quit()
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
  • 相关阅读:
    人物交互算法(HOI)学习笔记之 ——QPIC
    ??????
    国庆节难忘回家路:趣事、风景、反思
    Java-I/O输入输出
    PCL入门(六):深度图提取边界
    【SpringBoot】68、SpringBoot解决HttpServletRequest中输入流不能重复读的问题
    C++过河卒问题
    ElasticSearch高级功能详解与原理剖析
    检查两个数组在维度,形状以及元素值上是否均等价 numpy.array_equiv()
    【性能测试】Jenkins+Ant+Jmeter自动化框架的搭建思路
  • 原文地址:https://blog.csdn.net/weixin_44864919/article/details/134449807