zoukankan      html  css  js  c++  java
  • 为什么我还可以继续使用python自动填问卷星?

    1.由于问卷星系统的升级,利用selenium已经无法实现自动填写问卷.

     附(selenium源码):

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    import time
    import random
    def run():
        #1 问卷填报日期
        driver.find_element_by_id('q1').click()
        driver.switch_to.frame('__calendarIframe')
        time.sleep(1)
        driver.find_element_by_id('selectTodayButton').click()
        driver.switch_to.default_content()
        #2 体温测量日期
        driver.find_element_by_id('q2').click()
        driver.switch_to.frame('__calendarIframe')
        time.sleep(1)
        driver.find_element_by_id('selectTodayButton').click()
        driver.switch_to.default_content()
        #3 班级
        js = "document.getElementById("q3_1").click()"
        driver.execute_script(js)
        #4 学号
        driver.find_element_by_id('q4').send_keys("20183769")
        #5 姓名
        driver.find_element_by_id('q5').send_keys("赵常恒")
        #6 性别
        js="document.getElementById("q6_1").click()"
        driver.execute_script(js)
        #7 所在地区
        driver.find_element_by_xpath('//*[@id="divquestion7"]/ul/li[2]/a').click()
        #8 核酸
        driver.find_element_by_xpath('//*[@id="divquestion8"]/ul/li[1]/a').click()
        driver.find_element_by_xpath('//*[@id="divquestion8"]/ul/li[1]/input[2]').send_keys("1月7日阴性")
        #9 隔离情况
        js="document.getElementById("q9_2").click()"
        driver.execute_script(js)
        #10 密切接触
        js = "document.getElementById("q10_2").click()"
        driver.execute_script(js)
        #12 病例
        js = "document.getElementById("q12_2").click()"
        driver.execute_script(js)
        time.sleep(1)
        #14 体温
        num=random.randint(0,6)
        driver.find_element_by_id('q14').send_keys("36."+str(num)+"/"+"36."+str(num))
        time.sleep(1)
        #15 同住人员密切接触
        js = "document.getElementById("q15_2").click()"
        driver.execute_script(js)
        time.sleep(1)
        #17 同住人员病例
        js = "document.getElementById("q17_2").click()"
        driver.execute_script(js)
        time.sleep(1)
        #19 地理位置
        driver.find_element_by_id('q19').click()
        time.sleep(5)
        driver.switch_to.frame("PDF_i_chezchenz")
        time.sleep(1)
        # 1
        driver.find_element_by_id('txtInput').send_keys('河北省邢台市广宗县牛家寨村')
        time.sleep(1)
        driver.find_element_by_xpath('//*[@id="divauto"]/ul/li[1]').click()
        time.sleep(1)
        driver.find_element_by_xpath('//*[@id="divCurLoc"]/a').click()
        driver.switch_to.default_content()
        time.sleep(1)
        # 2
        #driver.find_element_by_xpath('//*[@id="mapcontainer"]/div[3]/div/div').click()
        #time.sleep(1)
        #driver.find_element_by_xpath('//*[@id="divCurLoc"]/a').click()
        #driver.switch_to.default_content()
        #20 居住地变化
        js="document.getElementById("q20_2").click()"
        driver.execute_script(js)
        time.sleep(1)
        #22 异常情况
        driver.find_element_by_id('q22').send_keys('')
        time.sleep(1)
        #23 同住人员
        driver.find_element_by_id('select2-q23-container').click()
        driver.find_element_by_xpath('/html/body/span/span/span[1]/input').send_keys('0')
        driver.find_element_by_xpath('/html/body/span/span/span[1]/input').send_keys(Keys.ENTER)
        time.sleep(10)
        #提交
    
    if __name__ == '__main__':
        driver = webdriver.Chrome()
        driver.get("***")
        run()
        # 提交
    selenium源码

     2.利用pyppeteer实现自动填写问卷操作

     附(pyppeteer源码):

    import asyncio
    from pyppeteer import launch
    from pyppeteer_stealth import stealth #反爬
    import random
    import time
    async def run():
        driver = await launch({
            # 谷歌浏览器的安装路径
            'executablePath': 'C:Program FilesGoogleChromeApplicationchrome.exe',
            # Pyppeteer 默认使用的是无头浏览器
            'headless': False,
            # 设置Windows-size和Viewport大小来实现网页完整显示
            'args': ['--no-sandbox', '--window-size=1024,768']
        })
        page = await driver.newPage()
        await page.setViewport({'width': 1024, 'height': 768})
        # 反爬虫跳入网页
        await stealth(page)
        await page.goto('***')
        time.sleep(1)
        #1 问卷填报日期
        date=await page.querySelector('#q1')
        await date.click()
        frame =page.frames
        date2= await frame[1].querySelector('#selectTodayButton')
        await date2.click()
        #2 体温测量日期
        date = await page.querySelector('#q2')
        await date.click()
        frame = page.frames
        date2 = await frame[1].querySelector('#selectTodayButton')
        await date2.click()
        #3 班级
        await page.click('#divquestion3 > ul > li > a')
        #4 学号
        await page.type('#q4','20183769')
        #5 姓名
        await page.type('#q5','赵常恒')
        # 6 性别
        await page.click('#divquestion6 > ul:nth-child(2) > li:nth-child(1) > a')
        #7 所在地区
        await page.click('#divquestion7 > ul > li:nth-child(2) > a')
        #8 核酸
        await page.click('#divquestion8 > ul > li:nth-child(1) > a')
        await page.type('#divquestion8 > ul > li:nth-child(1) > input.underline','第一次1月7日阴性,第二次1月11日阴性')
        #9 隔离情况
        await page.click('#divquestion9 > ul > li:nth-child(2) > a')
        #10 密切接触
        await page.click('#divquestion10 > ul:nth-child(2) > li:nth-child(2) > a')
        #12 病例
        await page.click('#divquestion12 > ul:nth-child(2) > li:nth-child(2) > a')
        #14 体温
        temperature="36."+str(random.randint(2,6))+'/'+"36."+str(random.randint(2,6))
        print(temperature)
        await page.type('#q14',temperature)
        #15 同住人员密切接触
        await page.click('#divquestion15 > ul:nth-child(2) > li:nth-child(2) > a')
        #17 同住人员病例
        await page.click('#divquestion17 > ul:nth-child(2) > li:nth-child(2) > a')
        #19 地理位置
        address= await page.querySelector('#q19')
        await address.click()
        time.sleep(5)
        frame=page.frames
        await frame[2].type('#txtInput','河北省邢台市广宗县牛家寨村')
        time.sleep(1)
        await frame[2].click('#btnSearch')
        time.sleep(1)
        await frame[2].click('#divauto > ul > li:nth-child(1) > div')
        time.sleep(1)
        await frame[2].click('.ensure_btn')
        #20 居住地变化
        await page.click('#divquestion20 > ul:nth-child(2) > li:nth-child(2) > a')
        # 22 异常情况
        await page.type('#q22','')
        #23 同住人员
        await page.click('#select2-q23-container')
        persion=await page.xpath('/html/body/span/span/span[2]/ul/li[2]')
        await persion[0].click()
        time.sleep(2)
        #提交
        await page.click('#submit_button')
    if __name__ == '__main__':
        asyncio.get_event_loop().run_until_complete(run())
    pyppeteer源码
  • 相关阅读:
    Bzoj 1010: [HNOI2008]玩具装箱toy(斜率优化)
    Cogs 376. [IOI2002]任务安排(后效性DP)
    Bzoj 1911: [Apio2010]特别行动队(斜率优化)
    Poj 2018 Best Cow Fences(分数规划+DP&&斜率优化)
    Bzoj 1212: [HNOI2004]L语言(AC自动机+DP)
    ZOJ 3228 Searching the String(AC自动机)
    Bzoj 3172: [Tjoi2013]单词(fail树)
    Hdu 3065 病毒侵袭持续中(AC自动机)
    Hdu 2896 病毒侵袭(AC自动机)
    Bzoj 2599: [IOI2011]Race(点分治)
  • 原文地址:https://www.cnblogs.com/zzmds/p/14276933.html
Copyright © 2011-2022 走看看