欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python 刷调查问卷

程序员文章站 2022-03-10 08:49:06
...
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from lxml import etree
import random
driver_path = r"C:\Users\top\Downloads\chromedriver_win32\chromedriver.exe"
driver = webdriver.Chrome(executable_path=driver_path)
#打开调查问卷网站
driver.get('https://www.wjx.cn/m/80563635.aspx')
time.sleep(2)
#1
js = 'document.getElementById("q1_%s").click()'%random.randint(1,2)
driver.execute_script(js)
time.sleep(2)
#2
a = random.randint(1,5)
b = random.sample([1,2,3,4,5],a)
for i in b:
    js = "document.getElementById('q2_%s').nextElementSibling.classList.add('jqchecked')" %i
    driver.execute_script(js)
#3
a = random.randint(1,2)
js = "document.getElementById('q3_%s').nextElementSibling.classList.add('jqchecked')"%a
driver.execute_script(js)
#4
a = random.randint(1,5)
b = random.sample([1,2,3,4,5],a)
for i in b:
    js = "document.getElementById('q4_%s').nextElementSibling.classList.add('jqchecked')" %i
    driver.execute_script(js)
#5
a = random.randint(1,2)
js = "document.getElementById('q5_%s').nextElementSibling.classList.add('jqchecked')" %a
driver.execute_script(js)
#6
a = random.randint(1,4)
b = random.sample([1,2,3,4],a)
for i in b:
    js = "document.getElementById('q6_%s').nextElementSibling.classList.add('jqchecked')" %i
    driver.execute_script(js)
#7
a = random.randint(1,4)
b = random.sample([1,2,3,4],a)
for i in b:
    js = "document.getElementById('q7_%s').nextElementSibling.classList.add('jqchecked')" %i
    driver.execute_script(js)
#8
a = random.randint(1,4)
b = random.sample([1,2,3,4],a)
for i in b:
    js = "document.getElementById('q8_%s').nextElementSibling.classList.add('jqchecked')" %i
    driver.execute_script(js)
#9
a = random.randint(1,5)
b = random.sample([1,2,3,4,5],a)
for i in b:
    js = "document.getElementById('q9_%s').nextElementSibling.classList.add('jqchecked')" %i
    driver.execute_script(js)
submit = driver.find_elements_by_css_selector('#ctlNext')[0]
submit.click()

本来还想着把线程加上,但貌似代码失败了,求大佬解答,论坛发不出去python 刷调查问卷