Home > other >  An error in the automatic questionnaire is how to return a responsibility?
An error in the automatic questionnaire is how to return a responsibility?

Time:02-19

The from the selenium import webdriver
From the time the import sleep
Import the random

# expected results (questionnaire to fill out to increase the proportion of these answers)
Experesult={' 0 ': 0,' 1 ', 1, '2' : 0, '3' : 1: '6' 0, '7' : 1, '9' : 1, '10' : 1, "11" : 1, "12" : 1, "13" : 1, '14' : 0,
'15', 0 '16' : 0, '17' : 0
, '18' : 0, '19:0,' 20 ': 0}


Def the select (k, I, t) :
"'
Randomly selected the answer, and increase the share of the answer given
"'
If the STR (I) in experesult. Keys () :
If % 1 k==0:
#, given the option of
Return experesult [STR (I))
The else:
# randomly selected a
Chic=random. Randint (0, t)
Return chic


# 10 times, (fill out 10 times)
For k in range (0, 10) :
# load Google browser
Browser=webdriver. Chrome ()
# loading page
The get (' https://wj.qq.com/s2/8047556/12c6/')
# get options
Lisbody=the find_elements_by_class_name (" question - the body ")
# get submit button
Submit=the find_element_by_class_name (" BTN - submit ")
# fill in the questionnaire
For I in range (0, 22) :
# get options
Listemp=lisbody [I] find_elements_by_class_name (" checkbox - option ")
An option # randomly selected
Ch=select (k, I, len (listemp) - 1)
# click
Listemp [ch]. Click ()
# submit
Submit. Click ()
Print (" first "+ STR (k + 1) +" time automatically completed ")
Close #
The close ()
# wait 1 seconds, the next fill out
sleep(1)
  • Related