代码成果演示
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.aspximport pyautoguifrom time import sleepimport pyperclipdef 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 且确保网络失常 确保浏览器关上的页面不超过1pyautogui.PAUSE=delay# pyautogui 每个函数调用提早 默认提早0.1秒completeQuestionnaire(text,delay,site)