脚本专栏 
首页 > 脚本专栏 > 浏览文章

Python3+Selenium+Chrome实现自动填写WPS表单

(编辑:jimmy 日期: 2024/11/19 浏览:3 次 )

引言

"_blank" href="https://chromedriver.storage.googleapis.com/index.html">ChromeDriver:从ChromeDriver镜像站里找到谷歌浏览器版本号对应的文件夹并打开,从中找到对应的系统后下载。"_blank" href="https://f.wps.cn/form-write/uwDUPB2N/">WPS表单。

Python3+Selenium+Chrome实现自动填写WPS表单

"text-align: left">"text-align: left">"htmlcode">

answer = wait.until(EC.element_to_be_clickable((By.ID, 'select_label_wrap_"htmlcode">
answer = wait.until(EC.element_to_be_clickable((By.ID, 'select_label_wrap_"htmlcode">
localtime = time.localtime(time.time())
if localtime.tm_hour < 7:
	t = 0
	print("填写时间为:0700-0900")
elif localtime.tm_hour < 11:
	t = 1
	print("填写时间为:1100-1200")
else:
	t = 2
	print("填写时间为:1800-2000")
answer = wait.until(EC.element_to_be_clickable((By.ID, 'select_label_wrap_"htmlcode">
answer = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.ant-calendar-picker')))
answer.click()
answer = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.ant-calendar-today-btn')))
answer.click()

"htmlcode">

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time

# WPS表单的网址
url = 'https://f.wps.cn/form-write/uwDUPB2N/'
# 完成浏览器对象的初始化,设定超时时间为10秒。
browser = webdriver.Chrome()
wait = WebDriverWait(browser, 10)
browser.get(url)

################################
# 针对INPUT组件,XXX替换成自己的内容。
answer = wait.until(EC.element_to_be_clickable((By.ID, 'input_0')))
answer.send_keys('XXX')
# 针对LABEL组件。
answer = wait.until(EC.element_to_be_clickable((By.ID, 'select_label_wrap_1_0')))
answer.click()
# 针对INPUT组件,XXX替换成自己的内容。
answer = wait.until(EC.element_to_be_clickable((By.ID, 'input_2')))
answer.send_keys('18')
# 针对LABEL组件。
answer = wait.until(EC.element_to_be_clickable((By.ID, 'select_label_wrap_3_0')))
answer.click()
# 针对PICKER组件。
answer = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.ant-calendar-picker')))
answer.click()
answer = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.ant-calendar-today-btn')))
answer.click()
# 针对询问时间的INPUT组件。
localtime = time.localtime(time.time())
if localtime.tm_hour < 7:
	t = 0
	print("填写时间为:0700-0900")
elif localtime.tm_hour < 11:
	t = 1
	print("填写时间为:1100-1200")
else:
	t = 2
	print("填写时间为:1800-2000")
answer = wait.until(EC.element_to_be_clickable((By.ID, 'select_label_wrap_5_' + str(t))))
answer.click()
################################

# 等待10秒
time.sleep(10)
# 点击提交
commit = wait.until(EC.element_to_be_clickable((By.ID, 'submit_button')))
commit.click()
# 确认提交
yes = wait.until(EC.element_to_be_clickable((By.ID, 'bind_phone_modal_confirm_button')))
yes.click()
# 反馈成功
print('Perfect!')

"htmlcode">

# 点击提交
commit = wait.until(EC.element_to_be_clickable((By.ID, 'submit_button')))
commit.click()
# 确认提交
yes = wait.until(EC.element_to_be_clickable((By.ID, 'bind_phone_modal_confirm_button')))
yes.click()

"htmlcode">

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
url = '填入WPS表单的网址'
browser = webdriver.Chrome()
wait = WebDriverWait(browser, 10)
browser.get(url)
answer = wait.until(EC.element_to_be_clickable((By.ID, 'input_0')))
answer.send_keys('XXX')
answer = wait.until(EC.element_to_be_clickable((By.ID, 'select_label_wrap_1_1')))
answer.click()
answer = wait.until(EC.element_to_be_clickable((By.ID, 'select_label_wrap_2_0')))
answer.click()
answer = wait.until(EC.element_to_be_clickable((By.ID, 'select_label_wrap_3_0')))
answer.click()
answer = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.ant-calendar-picker')))
answer.click()
answer = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, '.ant-calendar-today-btn')))
answer.click()
localtime = time.localtime(time.time())
if localtime.tm_hour < 7:
	t = 0
	print("填写时间为:0700-0900")
elif localtime.tm_hour < 11:
	t = 1
	print("填写时间为:1100-1200")
else:
	t = 2
	print("填写时间为:1800-2000")
answer = wait.until(EC.element_to_be_clickable((By.ID, 'select_label_wrap_5_' + str(t))))
answer.click()
answer = wait.until(EC.element_to_be_clickable((By.ID, 'input_6')))
answer.send_keys('36.6')
answer = wait.until(EC.element_to_be_clickable((By.ID, 'select_label_wrap_7_0')))
answer.click()
answer = wait.until(EC.element_to_be_clickable((By.ID, 'select_label_wrap_8_0')))
answer.click()
answer = wait.until(EC.element_to_be_clickable((By.ID, 'select_label_wrap_9_0')))
answer.click()
answer = wait.until(EC.element_to_be_clickable((By.ID, 'select_label_wrap_10_1')))
answer.click()
answer = wait.until(EC.element_to_be_clickable((By.ID, 'select_label_wrap_11_0')))
answer.click()
answer = wait.until(EC.element_to_be_clickable((By.ID, 'select_label_wrap_12_0')))
answer.click()
time.sleep(5)
commit = wait.until(EC.element_to_be_clickable((By.ID, 'submit_button')))
commit.click()
yes = wait.until(EC.element_to_be_clickable((By.ID, 'bind_phone_modal_confirm_button')))
yes.click()
print('Perfect!')

总结

以上所述是小编给大家介绍的Python3+Selenium+Chrome自动填写WPS表单,希望对大家有所帮助!

尾言

  最后,祝福武汉早日康复,武汉加油!

上一篇:适合Python初学者的一些编程技巧
下一篇:完美解决pycharm导入自己写的py文件爆红问题
荣耀猎人回归!七大亮点看懂不只是轻薄本,更是游戏本的MagicBook Pro 16.
人们对于笔记本电脑有一个固有印象:要么轻薄但性能一般,要么性能强劲但笨重臃肿。然而,今年荣耀新推出的MagicBook Pro 16刷新了人们的认知——发布会上,荣耀宣布猎人游戏本正式回归,称其继承了荣耀 HUNTER 基因,并自信地为其打出“轻薄本,更是游戏本”的口号。
众所周知,寻求轻薄本的用户普遍更看重便携性、外观造型、静谧性和打字办公等用机体验,而寻求游戏本的用户则普遍更看重硬件配置、性能释放等硬核指标。把两个看似难以相干的产品融合到一起,我们不禁对它产生了强烈的好奇:作为代表荣耀猎人游戏本的跨界新物种,它究竟做了哪些平衡以兼顾不同人群的各类需求呢?