Python selenium 모듈 아날로그 위챗 투표

7668 단어 파이썬 파충류
Python selenium 모듈 아날로그 위챗 투표
이 링크 안은 모두 선택 문제와 빈칸 채우기 문제이기 때문에 코드는 비교적 간단할 것이다
직접 부호:
import random
import xlrd from selenium import webdriver from selenium.webdriver.common.keys import Keys import time
def vote(username, work_num, iphone_no, list1, list2, list3, list4, driver): # driver = webdriver.Firefox() # # # if not count: # driver.get(“https://*******/Survey2/?id=61”) stop_time = 0.1 stop_time1 = 2 refresh_time = 1 time.sleep(stop time1) # 이름 # driver.find_element_by_id(“userName”).send_keys("장웨이") driver.find_element_by_id(‘userName’).send_keys("{}".format(username)) time.sleep(stop time) # 작업 번호 driver.find_element_by_id(“workerNum”).send_keys("{}".format(work_num)) time.sleep(stop time)#휴대폰 번호 driver.find_element_by_id(“phoneNum”).send_keys("{}".format(iphone_no)) time.sleep(stop_time)
#   1
driver.find_element_by_xpath('//input[@value="1" and @name="1558937665656"]').click()
time.sleep(stop_time)
#   2
driver.find_element_by_xpath('//input[@value="1" and @name="1558945701089"]').click()
time.sleep(stop_time)

#   13
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477711"]'.format(list3[0])).click()
time.sleep(stop_time)
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477711"]'.format(list3[1])).click()
time.sleep(stop_time)
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477711"]'.format(list3[2])).click()
# time.sleep(1)
# driver.find_element_by_xpath('//input[@value="3" and @name="1558958477711"]').click()
# time.sleep(1)
# driver.find_element_by_xpath('//input[@value="4" and @name="1558958477711"]').click()
# time.sleep(1)
# driver.find_element_by_xpath('//input[@value="5" and @name="1558958477711"]').click()
# time.sleep(1)
# driver.find_element_by_xpath('//input[@value="6" and @name="1558958477711"]').click()

#   14
driver.find_element_by_xpath('//input[@value="1" and @name="1558958477713"]').click()
time.sleep(stop_time)

#   15
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477714"]'.format(list4[0])).click()
# time.sleep(stop_time)
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477714"]'.format(list4[1])).click()
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477714"]'.format(list4[2])).click()
time.sleep(stop_time)

#   16
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477715"]'.format(list4[0])).click()
# time.sleep(stop_time)
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477715"]'.format(list4[1])).click()
# time.sleep(stop_time)
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477715"]'.format(list4[2])).click()
time.sleep(stop_time)

#   17
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477716"]'.format(list4[0])).click()
# time.sleep(stop_time)
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477716"]'.format(list4[1])).click()
# time.sleep(stop_time)
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477716"]'.format(list4[2])).click()
# time.sleep(stop_time)
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477716"]'.format(list4[3])).click()
time.sleep(stop_time)

#   18
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477717"]'.format(list1[0])).click()
time.sleep(stop_time)

#   19
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477718"]'.format(list1[0])).click()
time.sleep(stop_time)

#   20
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477719"]'.format(list1[0])).click()
# time.sleep(stop_time)

#   21
driver.find_element_by_xpath('//input[@value="{}" and @name="1558958477720"]'.format(list1[0])).click()
time.sleep(stop_time)

#   22
driver.find_element_by_xpath('//input[@value="3" and @name="1558958477721"]').click()
time.sleep(stop_time)

#   23
driver.find_element_by_xpath('//input[@value="0" and @name="1558958477722"]'.format(list1[0])).click()
time.sleep(stop_time)

#    24
# driver.find_element_by_class_name("fill").send_keys("          ")
# driver.find_element_by_xpath('//div[@index="24" and @class="fill-box" and @class="fill"]').send_keys("          ")
# driver.find_element_by_xpath('//div[@index="24"]/div[@class="fill-box"]/textarea').send_keys("  ")
# time.sleep(stop_time)

#   25
driver.find_element_by_xpath('//input[@value="1" and @name="1558958477724"]').click()
time.sleep(stop_time)

#    26
# driver.find_element_by_xpath('//div[@index="26"]/div[@class="fill-box"]/textarea').send_keys()
time.sleep(stop_time)
#
#    27
# driver.find_element_by_xpath('//div[@index="27"]/div[@class="fill-box"]/textarea').send_keys(" ")
# time.sleep(stop_time)
#
# #    28
# driver.find_element_by_xpath('//div[@index="28"]/div[@class="fill-box"]/textarea').send_keys(" ")
# time.sleep(stop_time)
#
# #    29
# driver.find_element_by_xpath('//div[@index="29"]/div[@class="fill-box"]/textarea').send_keys(" ")
# time.sleep(stop_time)

#       
driver.find_element_by_xpath("//span[@class='qsbtn submit']").click()
time.sleep(stop_time)

#   3 
time.sleep(refresh_time)

#        
driver.save_screenshot(u"vote.png")

# driver.back()
#
# driver.forward()
#
driver.refresh()
# driver.quit()

def getUserMsg (): filename = "ST RENYUAN.xlsx"# 데이터 읽기 = xlrd.open_workbook(filename) #sheet 획득 수량 #page=len(data.sheets() # 첫 번째 테이블table1 = data.sheets () [0] # 획득 총 줄 수 # nrows = table 1.nrows # 총 열 수 가져오기 # ncols = table 1.ncols # print(nrows, ncols) # print(page)
for i in range(200, 210):
    # print(table1.row_values(i)[1])
    yield table1.row_values(i)[1], table1.row_values(i)[2]

def getRandomData(list_, n): return random.sample(list_, n)
if name == “main”: a = getUserMsg() list1 = [1, 2]
#    4    
list2 = [1, 2, 3]

#    5    
list3 = [1, 2, 3, 4, 5]

#        7    
list4 = [2, 3, 4, 5, 6, 7]

#       
head = ["187", "159", "150", "137"]
list5 = ['0','1','2','3','4','5','6','7','8','9']

users = getUserMsg()

count = 0
driver = webdriver.Firefox()

# if not count:
driver.get("https://iedu.foxconn.com/Survey2/?id=61")
for user in users:
    iphone_no = getRandomData(head,1)+getRandomData(list5,8)
    iphone_no_ = ''.join(iphone_no)
    list1_ = getRandomData(list1,1)
    list2_ = getRandomData(list2, 2)
    list3_ = getRandomData(list2, 3)
    list4_ = getRandomData(list4, 4)
    count +=1

    vote(user[1], user[0], iphone_no_, list1_, list2_, list3_, list4_, driver)


driver.quit()

파이썬 파충류를 막 배웠으니, 여러분께서 많은 의견을 주시고, QQ2954538230을 추가하여 함께 토론하시기를 환영합니다.

좋은 웹페이지 즐겨찾기