通过python selenium + chromedriver刷网页邀请人数

原理:获取网页xpath 自动点击选项,填写表单提交试卷

刷题代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 刷题领礼物————BY:李志杰
import random
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By

from information import name, number_add_email, school


def answer(url, time, driver):#答题

sleep(3)
for i in range(4, 15, 2): # 题数
sleep(time)
xpath = '//*[@id="root"]/div/form/div[3]/div/div[' + str(i) + ']/div/div/div[2]/div[1]/div/span/div/div[' + str(
random.choice([1, 2, 3, 4])) + ']/div/div/label/span[1]'

driver.find_element(By.XPATH, value=xpath).click()
# 浏览器划到最底部
sleep(time)
driver.execute_script("window.scrollBy(0,2150)")
# 提交试卷
sleep(time)
driver.find_element(By.XPATH, '//*[@id="root"]/div/form/div[5]/button').click()
return driver


def form(driver, time):#填写表单
name_xpath = '//*[@id="root"]/div/form/div[3]/div[1]/div[4]/div/div/div[2]/div[1]/div/span/span/input'
school_xpath = '//*[@id="root"]/div/form/div[3]/div[1]/div[6]/div/div/div[2]/div[1]/div/span/span/input'
numbre_xpath = '//*[@id="root"]/div/form/div[3]/div[1]/div[8]/div/div/div[2]/div[1]/div/span/div/span/input'
over_xpath = '//*[@id="root"]/div/form/div[5]/div/button[2]'
sleep(time)
driver.find_element(By.XPATH, value=name_xpath).send_keys(name())
sleep(time)
driver.find_element(By.XPATH, value=school_xpath).send_keys(school())
sleep(time)
driver.find_element(By.XPATH, value=numbre_xpath).send_keys(number_add_email())
sleep(time)
driver.execute_script("window.scrollBy(0,2150)")
sleep(time)
driver.find_element(By.XPATH, value=over_xpath).click()


if __name__ == '__main__':
url = input('please input url:')
time = input('please input speed(S):')
n = input('please input frequency:')
for i in range(0, int(n), 1):
driver = webdriver.Chrome('/Users/a123456/Desktop/code/pythonProject/Brush_questions/chromedriver')
driver.get(url)
answer(str(url), int(time),driver) # 答题提交
sleep(int(time))
form(driver, int(time)) # 填写信息并提交
sleep(2)
driver.quit()
print('OVER!!!!!\nOpen html in check Number of peoples')



生成姓名,学号,手机号:information.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import random as r


def name():
# 随机姓名
first_name = ["张", "曾", "李", "王", "刘", "赵", "蒋", "孟", "陈", "徐", "杨", "沈", "马", "高", "殷", "欧阳"]
second_name = ["伟", "华", "建国", "洋", "刚", "万里", "爱民", "牧", "陆", "路", "昕", "鑫", "兵", "硕", "志宏", "峰", "磊", "雷", "文",
"明浩", "光", "超", "军", "达"]
# name = r.choice(first_name) + r.choice(second_name)
name = r.choice(first_name) + ''.join(r.choice(second_name))
return name


def school():
first_school = ["湖北", "河北", "山西", "辽宁", "吉林", "黑龙江", "江苏", "浙江"]
middle_school = ["工业", "农业", "邮电", '医药']
second_school = ["大学"]
school = r.choice(first_school) + ''.join(r.choice(middle_school)) + ''.join(r.choice(second_school))
return school


def number_add_email():
# 随机手机号
prelist = ["130", "131", "132", "133", "134", "135", "136", "137", "138", "139",
"147", "150", "151", "152", "153", "155", "156", "157", "158", "159",
"185", "187", "188", "189"]
# print(random.choice(prelist) + "".join(random.choice("0123456789") for i in range(8)))
num1 = r.choice(prelist) + ''.join(r.choice('0123456789') for i in range(8))
return num1