当前位置:   article > 正文

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

免费ip 问卷python

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

先看效果图:

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

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

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

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

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

userAgent.py代码

  1. import random
  2. userAgent = [
  3. "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",
  4. "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50",
  5. "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;",
  6. "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)",
  7. "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)",
  8. "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
  9. "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
  10. "Mozilla/5.0 (Windows NT 6.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1",
  11. "Opera/9.80 (Macintosh; Intel Mac OS X 10.6.8; U; en) Presto/2.8.131 Version/11.11",
  12. "Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11",
  13. "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",
  14. "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)",
  15. "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; TencentTraveler 4.0)",
  16. "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",
  17. "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; The World)",
  18. "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)",
  19. "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)",
  20. "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)",
  21. "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)",
  22. "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",
  23. "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",
  24. "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",
  25. "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",
  26. "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",
  27. "Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10",
  28. "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",
  29. "Mozilla/5.0 (BlackBerry; U; BlackBerry 9800; en) AppleWebKit/534.1+ (KHTML, like Gecko) Version/6.0.0.337 Mobile Safari/534.1+",
  30. "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",
  31. "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",
  32. "Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; HTC; Titan)",
  33. "UCWEB7.0.2.37/28/999",
  34. "NOKIA5700/ UCWEB7.0.2.37/28/999",
  35. "Openwave/ UCWEB7.0.2.37/28/999",
  36. "Mozilla/4.0 (compatible; MSIE 6.0; ) Opera/UCWEB7.0.2.37/28/999",
  37. ]
  38. def getRandomUserAgent():
  39. return random.choice(userAgent)

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

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

evaluate.py代码

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

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

proxy_ip.py代码

  1. import requests
  2. import json
  3. import time
  4. def getProxy():
  5. # 提取代理API接口,获取1个代理IP
  6. api_url = "" ====此处api_url需要填写代理的连接,填写后删掉等号和这句话即可====
  7. # 获取API接口返回的代理IP
  8. proxy_ip = json.loads(requests.get(api_url).text)
  9. ip_port = proxy_ip['data']['proxy_list'][0]
  10. #ip_port输出信息:60.163.20.29:44340,浙江|嘉兴,330400,139按照逗号分割
  11. list1 = str(ip_port).split(',')
  12. ip_port = list1[0]
  13. address = list1[1]
  14. postCode = list1[2]
  15. timeRemaining = list1[3]
  16. ipInfoDict = {
  17. "IP端口": ip_port,
  18. "地址": address,
  19. "邮编": postCode,
  20. "剩余时间(秒)": timeRemaining
  21. }
  22. # 白名单方式(需提前设置白名单)
  23. proxies = {
  24. "http": "http://%s/" % (ip_port),
  25. "https": "http://%s/" % (ip_port)
  26. }
  27. # 使用代理发送一个测试请求看看是否可用
  28. test_url = "https://www.baidu.com"
  29. try:
  30. response = requests.get(test_url, proxies=proxies)
  31. # 获取页面内容
  32. if response.status_code == 200:
  33. print("代理IP可用,信息如下:")
  34. #======若是其他家的代理,此处返回格式一定要相同,否则报错======
  35. print(ipInfoDict) #输出格式{'IP端口': '220.201.23.158:49365', '地址': '辽宁|抚顺', '邮编': '210400', '剩余时间(秒)': '161'}
  36. return proxies #返回代理格式:{'http': 'http://220.201.23.158:49365/', 'https': 'http://220.201.23.158:49365/'}
  37. else:
  38. print("代理IP不可用,延迟2秒重新获取")
  39. time.sleep(2)
  40. return getProxy()
  41. except:
  42. print("代理IP请求失败,延迟2秒重新获取")
  43. time.sleep(2)
  44. return getProxy()
  45. # if __name__ == '__main__':
  46. # 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代码

  1. import requests
  2. import time
  3. import random
  4. from datetime import datetime
  5. from proxy_ip import getProxy # 问卷星代理
  6. from evaluate import list_evaluate # 问卷星评价
  7. from userAgent import getRandomUserAgent # 问卷星随机UserAgent
  8. def serach(i,userAgent,proxies,question_id):
  9. url = "https://www.wjx.cn/joinnew/processjq.ashx"
  10. headers = {
  11. "Accept":"text/plain, */*; q=0.01",
  12. "Accept-Encoding":"gzip, deflate, br",
  13. "Accept-Language":"zh,zh-CN;q=0.9",
  14. "Connection":"keep-alive",
  15. "Content-Length":"231",
  16. "Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",
  17. "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.",
  18. "Host":"www.wjx.cn",
  19. "Origin":"https://www.wjx.cn",
  20. "Referer":"https://www.wjx.cn/vm/h7gO0Ks.aspx",
  21. "Sec-Ch-Ua":'"Chromium";v="118", "Google Chrome";v="118", "Not=A?Brand";v="99"',
  22. "Sec-Fetch-Dest":"empty",
  23. "Sec-Fetch-Mode":"cors",
  24. "Sec-Fetch-Site":"same-origin",
  25. "User-Agent":userAgent,
  26. "X-Requested-With":"XMLHttpRequest"
  27. }
  28. starttime = time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())
  29. cst = int(time.time()*1000)
  30. # 定义日期时间格式
  31. date_format = "%Y/%m/%d %H:%M:%S"
  32. # 将字符串转换为datetime对象
  33. dt = datetime.strptime(starttime, date_format)
  34. # 获取对应的Unix时间戳(转换为秒)
  35. timestamp_in_seconds = int(dt.timestamp())
  36. #随机900-1000秒是做问卷的时间,需要修改做问卷的时间请改下面的900-1000秒,不消耗本地时间
  37. spendtime = random.randint(900, 1000)
  38. timestamp_in_seconds = timestamp_in_seconds - spendtime
  39. print("问卷所用时间:" + str(spendtime) + "秒")
  40. # 转换为%Y/%m/%d %H:%M:%S
  41. starttime = datetime.fromtimestamp(timestamp_in_seconds).strftime(date_format)
  42. print("cst:" + str(cst))
  43. print("starttime:" + str(starttime))
  44. #做问卷的时间即cst-starttime 控制在150-300秒内
  45. params = {
  46. "shortid": question_id,#问卷ID
  47. "starttime": starttime, #开始时间
  48. "cst": cst, #当前时间戳
  49. "submittype": "1",
  50. "ktimes": "971",
  51. "hlv": "1",
  52. "rn": "660926024",
  53. "nw": "1",
  54. "jpm": "65",
  55. "t": cst + random.randint(39, 41), #当前时间戳
  56. "jqnonce": "5ec62e2c-6ab0-4628-9f19-70d2cf7090ed", #随机生成的问卷唯一标识
  57. "jqsign": "4db73d3b,7`c1,5739,8g08,61e3bg6181de", #随机生成的问卷表示加密,必须和上面是一对
  58. }
  59. #以下为问卷题目和选择答案的范围,修改question就要修改下面的data里的submitdata
  60. question1 = random.randint(1,2)
  61. question2 = random.randint(1,4)
  62. question3 = random.randint(1,6)
  63. question4 = random.randint(1,3)
  64. question5 = random.randint(1,3)
  65. question6_1 = random.choice([1,2,3])
  66. question6_2 = random.choice([4,5])
  67. question7_1 = random.choice([1,2,3])
  68. question7_2 = random.choice([4,5,6])
  69. question8 = random.randint(1,3)
  70. question9_1 = random.choice([1,2,3])
  71. question9_2 = random.choice([4,5])
  72. question10 = random.randint(1,5)
  73. question11 = random.randint(1,5)
  74. question12_1 = random.choice([1,2,3,4,5])
  75. question12_2 = random.choice([1,2,3,4,5])
  76. question12_3 = random.choice([1,2,3,4,5])
  77. question12_4 = random.choice([1,2,3,4,5])
  78. question12_5 = random.choice([1,2,3,4,5])
  79. question12_6 = random.choice([1,2,3,4,5])
  80. question12_7 = random.choice([1,2,3,4,5])
  81. question13_1 = random.choice([1,2,3,4,5])
  82. question13_2 = random.choice([1,2,3,4,5])
  83. question13_3 = random.choice([1,2,3,4,5])
  84. question13_4 = random.choice([1,2,3,4,5])
  85. question13_5 = random.choice([1,2,3,4,5])
  86. question13_6 = random.choice([1,2,3,4,5])
  87. question14_1 = random.choice([1,2,3])
  88. question14_2 = random.choice([4,5])
  89. question15_1 = random.choice([1,2,3])
  90. question15_2 = random.choice([4,5])
  91. question16 = random.randint(1,5)
  92. question17 = list_evaluate[i] #从评价列表中选择一条评价
  93. #data为提交问卷的数据
  94. data = {
  95. "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)
  96. }
  97. try:
  98. res = requests.post(url = url, headers = headers, data = data, params = params, proxies = proxies)
  99. if res.status_code == 200:
  100. print(res.url)
  101. else:
  102. print("提交失败")
  103. except:
  104. print("提交失败")
  105. if __name__ == "__main__":
  106. for i in range(0,100): #循环次数从第几次循环,到第几次结束,例如默认从第0此到第100次提交问卷
  107. print("第%d次提交" % (i+1))
  108. userAgent = getRandomUserAgent() #随机获取userAgent
  109. proxies = getProxy() #获取代理
  110. question_id = "mkA2TyN" #问卷ID ======此处需要修改为你的问卷id======
  111. serach(i,userAgent,proxies,question_id) #运行调查问卷函数
  112. delay = random.randint(30,40) #随机延迟30-40秒
  113. print("随机延迟%d秒" % delay)
  114. 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就可以了

运行结果图

最后强调

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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/605922
推荐阅读
相关标签
  

闽ICP备14008679号