当前位置: 首页 > 后端技术 > Python

自动完成调查

时间:2023-03-26 12:50:00 Python

代码效果演示Gitee源码#-*-coding:utf-8-*-#Version:Python3.9.7#Author:TRIX#Date:2021-09-1519:31:55#Use:自动完成问卷https://www.wjx.cn/jq/9132199.aspximportpyautoguifromtimeimportsleepimportpyperclipdefcompleteQuestionnaire(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)whileTrue:#检测页面上的所有按钮完全在一行buttonPos=pyautogui.locateCenterOnScreen('button1.jpg',region=(391,176,211,847),confidence=0.8)#识别图像区域(x,y,weight,height)confidencerecognitionaccuracy0-1ifbuttonPos:#如果检测到还没有被点击的按钮,pyautogui.click(buttonPos)#检测页面上所有的文本输入区域textAreaPos=pyautogui.locateCenterOnScreen('文本区域.jpg',region=(397,172,746,846),confidence=0.8)#识别图像区域(x,y,weight,height)confidence识别准确度0-1iftextAreaPos:#如果检测到未填充的文本输入区域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)#识别图片区域(x,y,weight,height)confidence识别准确度0-1ifsubmitPos:#如果检测到提交按钮,则本页已移至末尾pyautogui.hotkey('ctrl','home')#跳回页面开头#检测页面完成进度percentPos=pyautogui.locateCenterOnScreen('100.jpg',region=(1635,596,61,41),confidence=0.8)#识别图像区域(x,y,weight,height)confidence识别精度0-1ifpercentPos:#如果完成进度为100%pyautogui.hotkey('ctrl','end')#跳转到页尾sleep(0.5+delay)pyautogui.click(pyautogui.locateCenterOnScreen('submit.jpg',region=(872,709,134,74),confidence=0.8))#识别图像区域(x,y,weight,height)confidencerecognitionaccuracy0-1breakpyautogui.typewrite(['down'forninrange(3)])#scrolldown3gridstext='感觉不错,很爽,有种愉悦的感觉收获,但仍有提升空间。'delay=0.05#延迟设置为0.05秒site='https://www.wjx.cn/jq/9132199.aspx'pyautogui.FAILSAFE=True#如果程序运行失败,鼠标移到左上角的屏幕,将抛出pyautogui.FailSafeException并在使用前停止程序#ConfigureVideoConfig.txt并确保网络正常以确保浏览器打开的页面不超过1pyautogui.PAUSE=delay#pyautogui的每个函数调用延迟的默认延迟是0.1秒