python问卷星后台全自动做调查问卷(仅供学习参考,请勿商用)

这也是学校有任务,发现一个一个的推给同学做太麻烦了,学校要求量又太大,看了看大多数的自动做问卷发现都是用谷歌浏览器驱动模拟做题,这样效率太慢了,而且做题的ip都是一个人的,因此自己钻研了一个可以后台挂着的不同IP的全自动做问卷星调查问卷的程序

先看效果图:

注意,此方法仅适用于懂一点python基础的人,嫌麻烦的就不要继续往下看了

**********仅供学习参考,请勿商用,不听劝告,一切后果自负,与作者无关**********

下面附上代码并教给大家怎么使用,代码一共是四个文件,基本不用修改,分别是

问卷星(随机选项).py   proxy_ip.py  evaluate.py  userAgent.py

userAgent.py放的是爬虫时候的浏览器标识,这个无需修改,代码如下:

userAgent.py代码

import random
userAgent = [
    "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50",
    "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50",
    "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;",
    "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)",
    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
    "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
    "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11",
    "Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11",
    "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SE 2.X MetaSr 1.0; SE 2.X MetaSr 1.0; .NET CLR 2.0.50727; SE 2.X MetaSr 1.0)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)",
    "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",
    "Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
    "Mozilla/5.0 (iPod; U; CPU iPhone OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
    "Mozilla/5.0 (iPad; U; CPU OS 4_3_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8J2 Safari/6533.18.5",
    "Mozilla/5.0 (Linux; U; Android 2.3.7; en-us; Nexus One Build/FRF91) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
    "MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1",
    "Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10",
    "Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13",
    "Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+",
    "Mozilla/5.0 (hp-tablet; Linux; hpwOS/3.0.0; U; en-US) AppleWebKit/534.6 (KHTML, like Gecko) wOSBrowser/233.70 Safari/534.6 TouchPad/1.0",
    "Mozilla/5.0 (SymbianOS/9.4; Series60/5.0 NokiaN97-1/20.0.019; Profile/MIDP-2.1 Configuration/CLDC-1.1) AppleWebKit/525 (KHTML, like Gecko) BrowserNG/7.1.18124",
    "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)",
    "UCWEB7.0.2.37/28/999",
    "NOKIA5700/ UCWEB7.0.2.37/28/999",
    "Openwave/ UCWEB7.0.2.37/28/999",
    "Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999",
]

def getRandomUserAgent():
    return random.choice(userAgent)

evaluate.py这里面放得是问卷评价,需不需要取决于你的代码里有没有意见之类的让别人填写的东西没有的话就不需要,如下图就有需要填写的意见,因此需要多一个评价列表

评价列表里面的样式按照下面填写评论即可,代码如下:

evaluate.py代码

list_evaluate = [
    "无",
    "增加互动游戏和趣味挑战",      
    "",
    "提供多样化的表演和演出",      
    "无",  
    "提供免费WiFi方便游客分享体验",
    "提供特色民俗表演和体验",
    "加强卫生和清洁工作确保环境整洁",
    "推出庙会限定纪念品和邮票",
]

proxy_ip.py这里写的是问卷的代理,代码如下:

proxy_ip.py代码

import requests
import json
import time

def getProxy():
    # 提取代理API接口,获取1个代理IP
    api_url = ""   ====此处api_url需要填写代理的连接,填写后删掉等号和这句话即可====

    # 获取API接口返回的代理IP
    proxy_ip = json.loads(requests.get(api_url).text)
    ip_port = proxy_ip['data']['proxy_list'][0]
    #ip_port输出信息:60.163.20.29:44340,浙江|嘉兴,330400,139按照逗号分割
    list1 = str(ip_port).split(',')
    ip_port = list1[0]
    address  = list1[1]
    postCode = list1[2]
    timeRemaining = list1[3]
    ipInfoDict = {
        "IP端口": ip_port,
        "地址": address,
        "邮编": postCode,
        "剩余时间(秒)": timeRemaining
    }
    # 白名单方式(需提前设置白名单)
    proxies = {
        "http": "http://%s/" % (ip_port),
        "https": "http://%s/" % (ip_port)
    }

    # 使用代理发送一个测试请求看看是否可用
    test_url = "https://www.baidu.com"
    try:
        response = requests.get(test_url, proxies=proxies)
        # 获取页面内容
        if response.status_code == 200:
            print("代理IP可用,信息如下:")
            #======若是其他家的代理,此处返回格式一定要相同,否则报错======
            print(ipInfoDict) #输出格式{'IP端口': '220.201.23.158:49365', '地址': '辽宁|抚顺', '邮编': '210400', '剩余时间(秒)': '161'}
            return proxies #返回代理格式:{'http': 'http://220.201.23.158:49365/', 'https': 'http://220.201.23.158:49365/'}
        else:
            print("代理IP不可用,延迟2秒重新获取")
            time.sleep(2)
            return getProxy()
    except:
        print("代理IP请求失败,延迟2秒重新获取")
        time.sleep(2)
        return getProxy()


# if __name__ == '__main__':
#     print(getProxy())

代理ip我用的是免费的代理,每天可以白嫖1000个代理ip足够用了,当然你要有其他的方式可以用自己的,下面是作者的一个邀请链接,用户注册 - IP代理巨量ip代理为百家企业定制大数据http代理ip,巨量http代理有全国不限量动态ip代理/高匿http代理ip/socks5代理/长效静态代理ip/隧道代理等产品,完善的api和sdk赋能大数据爬虫,巨量代理企业首选。icon-default.png?t=N7T8https://www.juliangip.com/user/reg?inviteCode=1026512

获取免费额度后按照如下的方式进行提取代理ip

提取完后在下方设置使用代理ip的自己电脑上的ip

提取完代理ip的链接之后把申请的代理ip地址放入上面代码里的api_url的双引号里,并将“====此处api_url需要填写代理的连接,填写后删掉等号和这句话即可====”这句话删除即可

最后就是我们的做调查问卷的程序了

问卷星(随机选项).py代码

import requests
import time
import random
from datetime import datetime
from proxy_ip import getProxy # 问卷星代理
from evaluate import list_evaluate # 问卷星评价
from userAgent import getRandomUserAgent # 问卷星随机UserAgent

def serach(i,userAgent,proxies,question_id):
    url = "https://www.wjx.cn/joinnew/processjq.ashx"
    headers = {
        "Accept":"text/plain, */*; q=0.01",
        "Accept-Encoding":"gzip, deflate, br",
        "Accept-Language":"zh,zh-CN;q=0.9",
        "Connection":"keep-alive",
        "Content-Length":"231",
        "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
        "Cookie":".ASPXANONYMOUS=tCinauCg2gEkAAAAZTJlMzRjNWItZTUyNC00NjU0LWJkMDQtYjIyYWEwNDIwNmJm6cT43cuiP_HNHqKgljhbY_zE9P81; browserid=ecd510e4-9375-44f2-91f3-2418509a2f8f; WjxUser=UserName=13953838958; awardshowway5=1; awardshowway3=1; WjxUserPwd=WjxUserPwd=aVFUTm9EZFB2RU5GV2h2ROoE4epunkkwWNtrLdyk3ELveKQv0U5%2fT3Ulql71LnVyKD7WY70mM6atUAhShjIrKWdQhIYjf7wzJSvHh8lLs9H6ZXiE6B0GT1In3s%2f3UphYOKz%2bJGF9o4z%2fdOhzwqJgaQ%3d%3d; spiderregkey=haosou.com%c2%a7%e7%9b%b4%e8%be%be%c2%a71; awardshowway10=1; mqcount=4; awardshowway0=1; DeleteQCookie=1; crudat=2024-03-04 23:52:42; mobileuser=15725359308; lastshowway=2|2024-03-04 23:58; ASP.NET_SessionId=vndcc3eux1mzy14ytc5vhfcn; SojumpSurvey=0102AC09608BB53CDC08FEACA97112D73CDC0800184B623A672875376277007800730063006600760069006B0072005F00320034003000330030003400790031006E00720000012F00FFCCB4E2E8A239A604DDD038B5E982B85647BA8ABE; LastCheckUpdateDate=1; Hm_lvt_21be24c80829bd7a683b2c536fcf520b=1709555503,1709562029,1709567704,1709602961; ev_256499621=1; csrfck=34b2d4ea-35d1-4d04-8471-d1235e9d0f08; lastaccdate=2024-03-05 09:56:04; Hm_lpvt_21be24c80829bd7a683b2c536fcf520b=1709603765; SERVERID=c4b399ae928d1f610f814996e4778c43|1709603778|1709602928; tfstk=exjHjNj1Ww8CP8nfB6KQjhoIvx49AXtWN_nJw3dz7CRs9XndUbzldCIpyHJRq1fBh6dB46OPS_BWwbFhqNilhTsLd3eBA9tW4SFYDSBCd3M38M6bDTyr19NYMoE9BEyIcSQLhuCADGE7oCyPmJYDixduPbu7Fx5CLCmcC1JUzIZXr0ShXnAN4ddMBdIMKeAV4H0ZuoiEVokp04gW8d9MMOqbuLNAA3b7IR0cQeJ6Qa2gI4gW8d9MMR2ioO8eCd7l.",
        "Host":"www.wjx.cn",
        "Origin":"https://www.wjx.cn",
        "Referer":"https://www.wjx.cn/vm/h7gO0Ks.aspx",
        "Sec-Ch-Ua":'"Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99"',
        "Sec-Fetch-Dest":"empty",
        "Sec-Fetch-Mode":"cors",
        "Sec-Fetch-Site":"same-origin",
        "User-Agent":userAgent,
        "X-Requested-With":"XMLHttpRequest"
    }
    starttime = time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())
    cst = int(time.time()*1000)

    # 定义日期时间格式
    date_format = "%Y/%m/%d %H:%M:%S"
    # 将字符串转换为datetime对象
    dt = datetime.strptime(starttime, date_format)
    # 获取对应的Unix时间戳(转换为秒)
    timestamp_in_seconds = int(dt.timestamp())
    #随机900-1000秒是做问卷的时间,需要修改做问卷的时间请改下面的900-1000秒,不消耗本地时间
    spendtime = random.randint(900, 1000) 
    timestamp_in_seconds = timestamp_in_seconds - spendtime
    print("问卷所用时间:" + str(spendtime) + "秒")
    # 转换为%Y/%m/%d %H:%M:%S
    starttime = datetime.fromtimestamp(timestamp_in_seconds).strftime(date_format)
    print("cst:" + str(cst))
    print("starttime:" + str(starttime))
    #做问卷的时间即cst-starttime 控制在150-300秒内
    params = {
        "shortid": question_id,#问卷ID
        "starttime": starttime, #开始时间
        "cst": cst, #当前时间戳
        "submittype": "1",
        "ktimes": "971",
        "hlv": "1",
        "rn": "660926024",
        "nw": "1",
        "jpm": "65",
        "t": cst + random.randint(39, 41), #当前时间戳
        "jqnonce": "5ec62e2c-6ab0-4628-9f19-70d2cf7090ed", #随机生成的问卷唯一标识
        "jqsign": "4db73d3b,7`c1,5739,8g08,61e3bg6181de",  #随机生成的问卷表示加密,必须和上面是一对
    }
    #以下为问卷题目和选择答案的范围,修改question就要修改下面的data里的submitdata
    question1 = random.randint(1,2)
    question2 = random.randint(1,4)
    question3 = random.randint(1,6)
    question4 = random.randint(1,3)
    question5 = random.randint(1,3)
    question6_1 = random.choice([1,2,3])
    question6_2 = random.choice([4,5])
    question7_1 = random.choice([1,2,3])
    question7_2 = random.choice([4,5,6])
    question8 = random.randint(1,3)
    question9_1 = random.choice([1,2,3])
    question9_2 = random.choice([4,5])
    question10 = random.randint(1,5)
    question11 = random.randint(1,5)
    question12_1 = random.choice([1,2,3,4,5])
    question12_2 = random.choice([1,2,3,4,5])
    question12_3 = random.choice([1,2,3,4,5])
    question12_4 = random.choice([1,2,3,4,5])
    question12_5 = random.choice([1,2,3,4,5])
    question12_6 = random.choice([1,2,3,4,5])
    question12_7 = random.choice([1,2,3,4,5])
    question13_1 = random.choice([1,2,3,4,5])
    question13_2 = random.choice([1,2,3,4,5])
    question13_3 = random.choice([1,2,3,4,5])
    question13_4 = random.choice([1,2,3,4,5])
    question13_5 = random.choice([1,2,3,4,5])
    question13_6 = random.choice([1,2,3,4,5])
    question14_1 = random.choice([1,2,3])
    question14_2 = random.choice([4,5])
    question15_1 = random.choice([1,2,3])
    question15_2 = random.choice([4,5])
    question16 = random.randint(1,5)
    question17 = list_evaluate[i] #从评价列表中选择一条评价
    
    #data为提交问卷的数据
    data = {
        "submitdata": "1$"+str(question1)+"}2$"+str(question2)+"}3$"+str(question3)+"}4$"+str(question4)+"}5$"+str(question5)+"}6$"+str(question6_1)+"|"+str(question6_2)+"}7$"+str(question7_1)+"|"+str(question7_2)+"}8$"+str(question8)+"}9$"+str(question9_1)+"|"+str(question9_2)+"}10$"+str(question10)+"}11$"+str(question11)+"}12$1!"+str(question12_1)+",2!"+str(question12_2)+",3!"+str(question12_3)+",4!"+str(question12_4)+",5!"+str(question12_5)+",6!"+str(question12_6)+",7!"+str(question12_7)+"}13$1!"+str(question13_1)+",2!"+str(question13_2)+",3!"+str(question13_3)+",4!"+str(question13_4)+",5!"+str(question13_5)+",6!"+str(question13_6)+"}14$"+str(question14_1)+"|"+str(question14_2)+"}15$"+str(question15_1)+"|"+str(question15_2)+"}16$"+str(question16)+"}17$"+str(question17)
    }
    try:
        res = requests.post(url = url, headers = headers, data = data, params = params, proxies = proxies)
        if res.status_code == 200:
            print(res.url)
        else:
            print("提交失败")
    except:
        print("提交失败")

if __name__ == "__main__":
    for i in range(0,100): #循环次数从第几次循环,到第几次结束,例如默认从第0此到第100次提交问卷
        print("第%d次提交" % (i+1))
        userAgent = getRandomUserAgent()  #随机获取userAgent
        proxies = getProxy()   #获取代理
        question_id = "mkA2TyN"  #问卷ID   ======此处需要修改为你的问卷id======
        serach(i,userAgent,proxies,question_id)  #运行调查问卷函数
        delay = random.randint(30,40)  #随机延迟30-40秒
        print("随机延迟%d秒" % delay)
        time.sleep(delay)

需要修改的地方就是question_id的值,这是你调查问卷的id

如何获取这个id呢,如果你只有二维码那就扫描二维码获取链接的最后几位就是了,如下图我圈出来的就是id

然后需要修改的就是你问卷的题目:

这是问卷答案的顺序编号
对应下图,question1代表第1题,答案在random.randint(1,2)答案在1-2个选项之间随机选,当然也可以指定答案random.choice([1])这句话就是答案只在1里选,也就是答案就是第1个选项

你有多少个题就写多少个questionX,遇到多选题就写questionX_1,questionX_2,questionX_3等等以此类推,修改完后别忘下面的data是真正传上面question答案的地方,按照我的格式写就行

解释以下,1$就是第一题,str(question1)就是第1题的答案,多选题就用"|"分开和我上面给的格式一样就可以

这就大功告成了,运行的时候就运行这个问卷星(随机选项).py就可以了

运行结果图

最后强调

**********仅供学习参考,请勿商用,不听劝告,一切后果自负,与作者无关**********

  • 26
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值