使用selenium的webdriver,让Windows帮你自动填写web表单!

使用Python Selenium自动填写Windows上的Web表单
本文介绍如何利用Python的Selenium库编写脚本,自动填充和提交Web表单,包括环境配置、脚本编写、用PyInstaller打包成.exe文件以及设置Win10计划任务实现定时执行。

0. 引言

随着最近疫情的爆发,各个单位可能会要求大家每天填写健康问卷以确保健康安全。这些问卷的答案都是一样的,但是需要定时填写打卡,很容易某天就忘记了。因此,我们可以用python写一个脚本,让Windows每天自动帮我们填写。

一个问卷示例:
例如这样的一个问卷

1. 用selenium写一个自动填写表单的脚本

先上代码。

from selenium import webdriver
import selenium.webdriver.support.ui as ui
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
import selenium.webdriver.support.expected_conditions as EC

def filling():
    driver = webdriver.Chrome("chromedriver.exe")
    driver.get(r"https://表单链接")
    
    #    日期
    is_visible(driver, 'xpath_value1') #eg:'//*[@id="root"]/div/form/div[3]/div/div[2]/div/div[2]/div/div/span/div/div/input'
    driver.find_element_by_xpath('xpath_value1').click()
    is_visible(driver, 'xpath_value2')
    driver.find_element_by_xpath('xpath_value2').click()
    
    #    姓名
    driver.find_element_by_xpath('xpath_value3').send_keys("你的姓名")
    
    #    学号
    driver.find_element_by_xpath('xpath_value4').send_keys("你的学号")
    
    #    身体状况
    if driver.find_element_by_xpath('xpath_value5').is_selected():
        pass
    else:
        driver.find_element_by_xpath('xpath_value5').click()
    
    #    位置
    is_visible(driver, 'xpath_value6')
    driver.find_element_by_xpath(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值