其他分享
首页 > 其他分享> > 自动完成问卷调查

自动完成问卷调查

作者:互联网

代码效果演示
Gitee源码

# -*- coding: utf-8 -*-
# Version: Python 3.9.7
# Author: TRIX
# Date: 2021-09-15 19:31:55
# Use:自动完成问卷调查 https://www.wjx.cn/jq/9132199.aspx

import pyautogui
from time import sleep
import pyperclip
def completeQuestionnaire(text,delay,site):
	#上传视频 缩放比例为90% 分辨率1920x1080 固定坐标 执行操作有延迟 相应点击坐标不能大幅度改变
	#打开Edge浏览器
	pyautogui.click(160,1060)

	#切换输入法
	pyautogui.click(1802,1056)#点击输入法
	pyautogui.click(1720,780)#切换到中式键盘
	sleep(1.5+delay)

	#打开问卷调查网页
	pyperclip.copy(site)
	pyautogui.hotkey('ctrl','t')#打开新页面
	pyautogui.hotkey('ctrl','v')#粘贴网址
	pyautogui.press('enter')
	sleep(1.5+delay)

	while True:
	#检测页面所有 完全符合 按钮
		buttonPos=pyautogui.locateCenterOnScreen('button1.jpg',region=(391,176,211,847),confidence=0.8)#识别图片 region(x,y,weight,height) confidence识别精度0-1
		if buttonPos:#如果检测到了 还没有点击的 完全符合 按钮
			pyautogui.click(buttonPos)

	#检测页面所有 文本输入区域
		textAreaPos=pyautogui.locateCenterOnScreen('textArea.jpg',region=(397,172,746,846),confidence=0.8)#识别图片 region(x,y,weight,height) confidence识别精度0-1
		if textAreaPos:#如果检测到了 还没有填的 文本输入区域
			pyperclip.copy(text)
			pyautogui.click(textAreaPos)
			pyautogui.hotkey('ctrl','v')#粘贴
			pyautogui.click(1600,500)

	#检测页面的 提交按钮
		submitPos=pyautogui.locateCenterOnScreen('submit.jpg',region=(872,709,134,74),confidence=0.8)#识别图片 region(x,y,weight,height) confidence识别精度0-1
		if submitPos:#如果检测到了 提交按钮 则这一页移动到了末端
			pyautogui.hotkey('ctrl','home')#跳转回页面开头

	#检测页面的 完成进度
		percentPos=pyautogui.locateCenterOnScreen('100.jpg',region=(1635,596,61,41),confidence=0.8)#识别图片 region(x,y,weight,height) confidence识别精度0-1
		if percentPos:#如果完成进度 100%
			pyautogui.hotkey('ctrl','end')#跳转页面结尾
			sleep(0.5+delay)
			pyautogui.click(pyautogui.locateCenterOnScreen('submit.jpg',region=(872,709,134,74),confidence=0.8))#识别图片 region(x,y,weight,height) confidence识别精度0-1
			break
		pyautogui.typewrite(['down' for n in range(3)])#向下滚动3格


text='感觉很好,让人耳目一新,有一种丰收的喜悦,但仍然有提升空间。'
delay=0.05#延迟设置为0.05秒
site='https://www.wjx.cn/jq/9132199.aspx'

pyautogui.FAILSAFE=True# 如果程序出错 鼠标移动到屏幕左上角 抛出 pyautogui.FailSafeException 异常 并停止程序
#使用之前 先配置 VideoConfig.txt 且确保网络正常 确保浏览器打开的页面不超过1
pyautogui.PAUSE=delay# pyautogui 每个函数调用延迟 默认延迟0.1秒
completeQuestionnaire(text,delay,site)

标签:pyautogui,confidence,region,click,delay,自动,完成,识别,问卷调查
来源: https://www.cnblogs.com/Trix/p/15305981.html