问卷星最新调研爬虫自动填写

利用简单权重设置选项比例分配以及条件判断语句即可将问卷往你选择的放向走,需要对前端稍微了解即可,用谷歌的开发者工具查看元素

例如:check = rank[i].find_elements(by=By.CLASS_NAME,value="ui-radio")

from selenium import webdriver
import random
import time
import numpy as np
#pip install selenium==4.8.0 最新版本模块
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver import ActionChainsdef get_ele_time(driver,time,func):WebDriverWait(driver,time).until(func)
def auto_write():# 防止被浏览器识别为脚本# 需要谷歌版本 109.0.5414.120(正式版本) (64 位),否则可能会报错chrome_options = Options()chrome_options.add_argument("--disable-blink-features=AutomationControlled")chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])chrome_options.add_argument('user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36')driver = Chrome(options=chrome_options)#这里需要你写下你的问卷星的网址进行调研虫,例如我们的问卷driver.get('https://www.wjx.cn/vm/OpWPWY1.aspx#')# print('=============================================================')# 获取到所有题目的选项rank = driver.find_elements(by=By.CLASS_NAME,value="field.ui-field-contain")mins=0mins_one=0mins_two=0mins_three=0mins_four=0mins_five=0mins_six=0mins_seven=0mins_eight=0mins_night=0# print(len(rank))for i in range(0,len(rank)):type_q = rank[i].get_attribute("type")# print(type_q)# 单选if(type_q == '3'):if(i==15):check = rank[i].find_elements(by=By.CLASS_NAME,value="ui-radio")mins = random.randint(0,len(check)-2)# print(type(check))check[mins].click()# check='null'elif(i==0):check = rank[i].find_elements(by=By.CLASS_NAME,value="ui-radio")alist = [0, 1]weight = [0.6,0.4]choiceNum = random.choices(alist, weights=weight)mins = choiceNum[0]check[mins].click()# flag=True# check = rank[i].find_elements(by=By.CLASS_NAME,value="ui-radio")# # print(type(check))# while(flag):#     mins = random.randint(0,len(check)-1)#     # print(mins)#     if(mins==1 or mins==2):#         flag=True#         # mins = random.randint(0,len(check)-1)#         # check[mins].click()#     else:#         check[mins].click()#         flag=Falseelif(i==1):check = rank[i].find_elements(by=By.CLASS_NAME,value="ui-radio")#利用权重对选项进行选择alist = [0, 1, 2, 3, 4, 5]weight = [0,0,0.5,0.35,0.15,0]choiceNum = random.choices(alist, weights=weight)mins_one = choiceNum[0]check[mins_one].click()elif(i==2):check = rank[i].find_elements(by=By.CLASS_NAME,value="ui-radio")alist = [0, 1, 2, 3, 4]weight = [0.2,0.5,0.3,0,0]choiceNum = random.choices(alist, weights=weight)mins_two = choiceNum[0]check[mins_two].click()elif(i==3):check = rank[i].find_elements(by=By.CLASS_NAME,value="ui-radio")print(mins_one)if(mins_one==2):alist = [0, 1, 2, 3, 4,5,6,7]weight = [0,0.28,0.2,0.38,0.12,0.02,0,0]choiceNum = random.choices(alist, weights=weight)mins_three = choiceNum[0]check[mins_three].click()if(mins_one==3):alist = [0, 1, 2, 3, 4,5,6,7]weight = [0,0.2,0.36,0.24,0.18,0.02,0,0]choiceNum = random.choices(alist, weights=weight)mins_three = choiceNum[0]check[mins_three].click()if(mins_one==4):alist = [0, 1, 2, 3, 4,5,6,7]weight = [0,0.2,0.36,0.24,0.18,0.02,0,0]choiceNum = random.choices(alist, weights=weight)mins_three = choiceNum[0]check[mins_three].click()elif(i==4):check = rank[i].find_elements(by=By.CLASS_NAME,value="ui-radio")if(mins_three==1):alist = [0, 1, 2, 3, 4,5,6]weight = [0,0.05,0.15,0.4,0.3,0.05,0.05]choiceNum = random.choices(alist, weights=weight)mins_four = choiceNum[0]check[mins_four].click()if(mins_three==2):alist = [0, 1, 2, 3, 4,5,6]weight = [0.02,0.1,0.2,0.4,0.3,0.1,0.1]choiceNum = random.choices(alist, weights=weight)mins_four = choiceNum[0]check[mins_four].click()if(mins_three==3):alist = [0, 1, 2, 3, 4,5,6]weight = [0,0.05,0.2,0.4,0.3,0.1,0.1]choiceNum = random.choices(alist, weights=weight)mins_four = choiceNum[0]check[mins_four].click()if(mins_three==4):mins_four=random.randint(0,6)check[mins_four].click()if(mins_three==5):mins_four=0check[mins_four].click()if(mins_three==6):mins_four=random.randint(0,1)check[mins_four].click()if(mins_three==7):mins_four=random.randint(0,6)check[mins_four].click()elif(i==5):check = rank[i].find_elements(by=By.CLASS_NAME,value="ui-radio")if(mins==1):alist = [0, 1, 2, 3, 4,5,6,7,8]weight = [0.05,0.02,0.1,0.05,0.2,0.3,0.05,0.05,0.08]choiceNum = random.choices(alist, weights=weight)mins_five = choiceNum[0]check[mins_five].click()if(mins==0):alist = [0, 1, 2, 3, 4,5,6,7,8]weight = [0.12,0.3,0.12,0.12,0.1,0,0.12,0.1,0.02]choiceNum = random.choices(alist, weights=weight)mins_five = choiceNum[0]check[mins_five].click()elif(i==6):check = rank[i].find_elements(by=By.CLASS_NAME,value="ui-radio")alist = [0, 1, 2, 3, 4]weight = [0.45,0.1,0.05,0.2,0.2]choiceNum = random.choices(alist, weights=weight)mins_six= choiceNum[0]check[mins_six].click()elif(i==7):check = rank[i].find_elements(by=By.CLASS_NAME,value="ui-radio")alist = [0, 1, 2, 3, 4]weight = [0.3,0.4,0.15,0.1,0.05]choiceNum = random.choices(alist, weights=weight)mins_seven= choiceNum[0]check[mins_seven].click()elif(i==8):check = rank[i].find_elements(by=By.CLASS_NAME,value="ui-radio")if(mins_seven==0):mins_eight=random.randint(0,4)check[mins_eight].click()if(mins_seven==1):mins_eight=random.randint(1,4)check[mins_eight].click()if(mins_seven==2):mins_eight=random.randint(2,4)check[mins_eight].click()if(mins_seven==3):mins_eight=random.randint(3,4)check[mins_eight].click()if(mins_seven==4):mins_eight=4check[mins_eight].click()elif(i==9):check = rank[i].find_elements(by=By.CLASS_NAME,value="ui-radio")alist = [0, 1, 2, 3, 4]weight = [0.01,0.6,0.3,0.07,0.02]choiceNum = random.choices(alist, weights=weight)mins_night= choiceNum[0]check[mins_night].click()                    #     多选if(type_q == '4'):ui_check = rank[i].find_elements(by=By.CLASS_NAME,value="label")length = len(ui_check)# print(length)for k in range(len(ui_check)):# 如果多选中填空题选项不叫其他,请更改此行代码if ui_check[k].text == '其他':length = length-1# 如果多选规定选择的项数请修改下面的random_choice = np.random.randint(0,length,size=random.randint(1,length))for z in list(set(random_choice)):ui_check[z].click()#         量表if(type_q == '5'):lb_data = rank[i].find_elements(by=By.CLASS_NAME,value="td")lb_data[random.randint(0,len(lb_data)-1)].click()#     矩阵量表if(type_q == '6'):# print(rank[i].text)if(i==13):mat_data = rank[i].find_elements(by=By.CSS_SELECTOR,value="tr[tp=d]")# print(len(mat_data))# mat_data = rank[i].find_elements_by_xpath("./tbody/tr[@tp=\"d\"]")for s in range(0,len(mat_data)):single_mat_row = mat_data[s].find_elements(by=By.CLASS_NAME,value='rate-off.rate-offlarge')# print(len(single_mat_row))# check = rank[i].find_elements(by=By.CLASS_NAME,value="ui-radio")alist = [0, 1, 2, 3, 4]weight = [0.5,0.3,0.3,0.15,0.05]choiceNum = random.choices(alist, weights=weight)[0]single_mat_row[choiceNum].click()elif(i==14):mat_data = rank[i].find_elements(by=By.CSS_SELECTOR,value="tr[tp=d]")# print(len(mat_data))# mat_data = rank[i].find_elements_by_xpath("./tbody/tr[@tp=\"d\"]")for s in range(0,len(mat_data)):single_mat_row = mat_data[s].find_elements(by=By.CLASS_NAME,value='rate-off.rate-offlarge')# print(len(single_mat_row))# check = rank[i].find_elements(by=By.CLASS_NAME,value="ui-radio")alist = [0, 1, 2, 3, 4]weight = [0.05,0.15,0.3,0.3,0.5]choiceNum = random.choices(alist, weights=weight)[0]single_mat_row[choiceNum].click()else:mat_data = rank[i].find_elements(by=By.CSS_SELECTOR,value="tr[tp=d]")# print(len(mat_data))# mat_data = rank[i].find_elements_by_xpath("./tbody/tr[@tp=\"d\"]")for s in range(0,len(mat_data)):single_mat_row = mat_data[s].find_elements(by=By.CLASS_NAME,value='rate-off.rate-offlarge')# print(len(single_mat_row))alist = [0, 1, 2, 3, 4]weight = [0.05,0.15,0.3,0.5,0.7]choiceNum = random.choices(alist, weights=weight)[0]# single_mat_row[choiceNum].click()single_mat_row[choiceNum].click()driver.find_element(by=By.ID,value="ctlNext").click()# XPATH='//*[@id="layui-layer1"]/div[3]/a[1]'# 消除确认弹窗time.sleep(random.randint(2, 5))# js = 'document.getElementById("alert_box").style.display="none";'driver.find_element(by=By.CLASS_NAME,value="layui-layer-btn0").click()# time.sleep(0.5)time.sleep(random.randint(3, 7))# driver.execute_script(js)# 点智能验证提示框,进行智能验证driver.find_element(by=By.XPATH,value="//div[@id='rectMask']").click()time.sleep(random.randint(2, 15))driver.quit()  # 运行完毕自动关闭浏览器# driver.quit()if __name__ == '__main__':for i in range(1,1001):print("正在填写第{}份问卷".format(i))auto_write()print("第{}份问卷已经填写完成".format(i))time.sleep(random.randint(2,6))#此处需要停留20分钟,建议晚上挂机刷问卷if(i%20==0):time.sleep(1200)

最后的结果:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.rhkb.cn/news/44964.html

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

仿造问卷星--开发一套调查问卷设计工具(2/3)--完整流程

本章主要内容是完善index.js逻辑功能。 1&#xff0c;修改index.html&#xff0c;直接copy html和css文件直接从源码中拷贝&#xff1a; html <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8" /><meta http-eq…

Python自动化问卷填写-问卷星(含完整代码)

目录 一、环境安装二、代码分析&#xff08;一&#xff09;库的引用&#xff08;二&#xff09;驱动的运行&#xff08;三&#xff09;各类题型的程序&#xff08;四&#xff09;主程序&#xff08;根据问卷客制&#xff09; 三、完整代码 由于网上的问卷星填写代码良莠不齐&am…

Python自动化填写问卷星问卷

本文使用pyhton实现常见的问卷星问卷自动化填写。如果出现智能验证&#xff0c;本文还不能有效绕过问卷星提交时出现的智能检测&#xff0c;还需要手动点击智能检测才能完成问卷的填写。 在网络问卷中&#xff0c;我们常见的问题有单选题、多选题和李克勤量表题&#xff0c;如下…

python自动填写问卷星

python自动填写问卷星 参考链接1 参考链接2 用python实现自动填问卷&#xff0c;通过智能验证以及滑动验证 1. 下载浏览器驱动 python自动化填写问卷需要依赖浏览器驱动,这里使用的是谷歌浏览器&#xff0c;所以需要下载chromedriver&#xff0c;且下载的版本要和浏览器版本…

问卷星问卷数据怎么快速导入SPSSAU?

最近收到小伙伴询问问卷星导入的问卷数据怎么编码&#xff1f; 现在的问卷调查&#xff0c;很多都是通过网络问卷的方式进行&#xff0c;问卷星是一个专业的在线问卷调查、测评投票平台&#xff0c;如果你的问卷正好是在问卷星网站发放&#xff0c;填答&#xff0c;回收数据&am…

python问卷星模拟提交

*一、前言 ** 笔者在家闲得无聊&#xff0c;突然想突破一下问卷星的反爬虫机制&#xff0c;顺便刷刷问卷&#xff0c;于是就开始分析了。 ** 二、分析过程 ** 1、fiddler抓包 模拟提交首先当然是打开fiddler看看提交了什么包啦。 2、分析不变参数 我们先来看不变的参数&…

使用python实现问卷星自动答题功能——基础篇

题主在学习的过程中&#xff0c;老是有人来让填问卷星&#xff0c;就觉得人填的很麻烦&#xff0c;于是就自己动手写了一个python脚本来实现自动填写问卷星 1.首先我们得学会使用python里面的一个库&#xff0c;selenium&#xff0c;这个库是用来专门面对浏览器的一个库&#…

用Python实现问卷星自动填写(超详细!!!)

用Python实现问卷星自动填写&#xff08;超详细&#xff01;&#xff01;&#xff01;&#xff09; 前言一、配置环境1.1安装依赖1.2安装驱动 二、实战处理2.1、引入库函数2.2、程序所需函数详解&#xff08;1&#xff09;自定义单选函数&#xff08;2&#xff09;自定义多选函…

自动填写问卷星并提交

自动填写问卷星并提交 鉴于好多小伙伴要做数据分析的时候发放大量的问卷&#xff0c;但收回来的却寥寥无几&#xff0c;还受到其他小伙伴的冷眼&#xff0c;所以在下决定通过代码的方式&#xff0c;来实现问卷星的自动填写并提交。 以谷歌浏览器为例 1.随便到一个页面&#x…

【python】自动填写问卷星问卷及提交

前言&#xff1a;问卷是很好的网络调查方式之一&#xff0c;近年来&#xff0c;问卷星被广泛应用于各方面的调查。本文介绍了利用python代码自动填写问卷星基本题目&#xff0c;拥有自动填写、解决智能验证、批量提交问卷等功能。 目录 1.下载浏览器驱动 2. selenium基本配置…

利用GoogleTampermonkeyModify Headers实现问卷星调查问卷的自动填写提交

前言 首先一个月没有更新博客&#xff0c;是因为去苏州尝试了一下暑假工&#xff0c;然后对于大家在博客留下的评论和问题也没有来得及回复&#xff0c;实在不好意思。不得不说&#xff0c;暑假工挺累的&#xff0c;而且基本上在消磨时间&#xff0c;说实话也不算后悔&#xf…

Python实现问卷星调查问卷自动填写

文章目录 前言一、配置环境1.1 下载依赖selenium1.2 安装chrome驱动1.3 引入库 二、简易版快速上手教程1.自定义变量2.自定以函数3 主函数编写 三 逐步解析1 基础代码2 实现步骤 四 代码总结 前言 如何使用python实现对问卷的自动填写提交任务并且还能解决智能验证问题。 一、…

Mac 软件出现「意外退出」及「打不开」解决方法

解决方法 方法其实有很多种&#xff0c;这里介绍常用的几种 终端法需先安装Xcode或Apple命令行工具 如未装Xcode可以使用下列命令安装Apple命令行工具&#xff08;如安装有Xcode可忽略&#xff09; xcode-select --install 1.终端法 sudo codesign --force --deep --sign -…

postman能正常打开但不显示窗口

1.最近使用postman偶尔出现以下问题 postman在任务栏能正常打开&#xff0c;如下图&#xff0c;使用AltTab也能看到&#xff0c;但是窗口就是显示不了 2.解决方案 将鼠标放在任务栏上&#xff0c;使用快捷键Alt空格&#xff0c;弹出小窗口&#xff0c;然后点击弹框中的最大化…

MPAndroidChart的HorizontalBarChart数值显示不全问题

现在使用的版本是&#xff1a;v3.1.0 方案一&#xff1a; private HorizontalBarChart hor_bar_chart; hor_bar_chart(HorizontalBarChart) findViewById(R.id.hor_barchart); YAxis leftYAxishor_bar_chart.getAxisLeft(); // 设置y轴边距&#xff0c;解决数值过大显示不全问…

解决 echarts 图中 tooltip 文本内容太长导致显示不全

问题&#xff1a; 使用 tooltip 的 extraCssText&#xff0c;高效方便 tooltip: {show:true,trigger: "axis",confine: true, // 文本太长自动换行extraCssText: white-space: normal; word-break: break-all;, // 文本太长自动换行效果&#xff1a;

CoordinatorLayout显示不全问题

问题一 <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android"http://schemas.android.com/apk/res/android"xmlns:app"http://schemas.android.com/apk/res-auto"android:layout_width"match_parent"android:layout_height&…

在html中页面不全,网页显示不全,教您网页显示不全怎么办

当我们在电脑系统中使用IE浏览器浏览网页时&#xff0c;偶尔会出现是否只查看安全内容的提示&#xff0c;甚至有可能会出现页面显示不全的情况。一般遇到这种情况会选择继续查看网页内容&#xff0c;怎么去处理&#xff1f;下面&#xff0c;小编给大家介绍网页显示不全的解决步…

CSS问题:导航栏设置通栏后,放大页面背景显示不全

问题描述&#xff1a; 正常显示时&#xff1a;将网页放大到150%后&#xff1a; 解决办法&#xff1a; 当导航栏设置为width:100%或不给宽&#xff0c;是相当于当前文档流而言的&#xff0c;也就是浏览器窗口的大小。 此时假设浏览器窗口大小为1000px&#xff0c;那么这个通栏…