去年的纯后台版挂了,今年发现有nvcVal的验证,还在破解逻辑中...
2022.10.30 更新 & 答疑
浏览器请使用360极速最新版本(它更新的慢,最新的和我的一样),因为我的selenuim是老版本的,webdriver也是,所以有兼容问题
2022.10.19 更新
只能完成一个的试试用360极速浏览器,浏览器兼容的问题(大概)
其实这个用油猴插件更方便,更兼容,可以我不会编写插件....
取巧用seleuim弄了一个,网速好的话5,6s都可以,一般10s一个
使用步骤
考虑到使用有些复杂,准备出个视频版的教程和资源整合包,比较忙还没录视频,现在就先看着吧.....会用的自己就可以用了
1.安装python
2.安装python运行所需要的模块
3.移动selenium驱动文件到指定地点
4.要登录的账号进行配置
1.安装
python官网下载双击打开,记得勾选path
2.安装模块
用的有两个selenium,requests
3.下载对应浏览器的selenium驱动,放到浏览器目录下
你用的哪个浏览器就放到哪个浏览器下面去
4.要登录的账号进行配置
先去第二课堂把账号密码列表下载下来,是excel的
然后把账号密码放到python文件夹下的 账户.txt 文件夹里面
最后点击运行即可
旧版本代码
from selenium import webdriver
import time
import json
import requests
import random
requests.packages.urllib3.disable_warnings()
# 设置driver路径,这个是我的浏览器路径,要改成你的
location = r'D:\我的程序\360极速\360Chrome\Chrome\Application\360chrome.exe'
# selenium设置与启动
options = webdriver.ChromeOptions()
prefs = {"profile.managed_default_content_settings.images": 2} # 无图模式访问,这样的话加载会快很多
options.add_experimental_option("prefs", prefs)
options.binary_location = location
driver=webdriver.Chrome(chrome_options=options)
driver.get('https://www.2-class.com/competition')
# 这里是等待加载完成才这样设置的
time.sleep(5)
def login(account):
#点击登录
el = driver.find_element_by_xpath('//*[@id="app"]/div/div[1]/div/header/div/div[2]/div[2]/div/span/a')
el.click()
time.sleep(2)
#account
el = driver.find_element_by_xpath('//*[@id="account"]')
el.send_keys(account)
print(account)
time.sleep(1)
#password
el = driver.find_element_by_xpath('//*[@id="password"]')
el.send_keys('a1234567')
#登录
el = driver.find_element_by_css_selector("[type='submit']")
el.click()
time.sleep(2)
#cookie和数据
cookie = ''
cookies=driver.get_cookies()
for i in cookies:
cookie = cookie + i['name'] + '=' + i['value'] + ';'
reqtoken = driver.execute_script('return window.__DATA__.reqtoken')
yi_jian_man_fen(cookie,reqtoken,account)
#点击退出
el = driver.find_element_by_xpath('//*[@id="app"]/div/div[1]/div/header/div/div[2]/div[2]/div/a')
el.click()
time.sleep(1)
el = driver.find_element_by_xpath('//*[@id="app"]/div/div[1]/div/header/div/div[2]/div[2]/div/div/ul/li[6]/a')
el.click()
time.sleep(2)
#开始答题
def yi_jian_man_fen(cookie,reqtoken,account):
url = 'https://www.2-class.com/api/quiz/commit'
headers = {
'Cookie': cookie,
'Content-Type': 'application/json',
'User-Agent': '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'
}
time = random.randint(100, 350)
data = {
"list": [
{
"questionId": 2986,
"questionContent": "B"
},
{
"questionId": 2989,
"questionContent": "C"
},
{
"questionId": 2990,
"questionContent": "D"
},
{
"questionId": 2959,
"questionContent": "C"
},
{
"questionId": 2928,
"questionContent": "C"
},
{
"questionId": 2960,
"questionContent": "A"
},
{
"questionId": 2961,
"questionContent": "C"
},
{
"questionId": 2897,
"questionContent": "B"
},
{
"questionId": 2930,
"questionContent": "D"
},
{
"questionId": 2898,
"questionContent": "B"
},
{
"questionId": 2963,
"questionContent": "A"
},
{
"questionId": 2932,
"questionContent": "D"
},
{
"questionId": 2901,
"questionContent": "A"
},
{
"questionId": 2966,
"questionContent": "D"
},
{
"questionId": 2934,
"questionContent": "C"
},
{
"questionId": 2904,
"questionContent": "D"
},
{
"questionId": 2907,
"questionContent": "D"
},
{
"questionId": 2972,
"questionContent": "C"
},
{
"questionId": 2973,
"questionContent": "A"
},
{
"questionId": 2912,
"questionContent": "B"
}
],
"time": time,
"reqtoken": reqtoken
}
result = requests.post(url=url, data=json.dumps(data), headers=headers, verify=False)
print(account + '已经完成')
if __name__ == '__main__':
accounts = []
with open('账户.txt','r') as f:
accounts = f.read().split('\n')
try:
for account in accounts:
login(account)
except:
print('程序运行错误')
driver.quit() # 使用完, 记得关闭浏览器, 不然chromedriver.exe进程为一直在内存中.
新版本代码(滑动待定)
from selenium import webdriver
import time
import json
import requests
import random
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
requests.packages.urllib3.disable_warnings()
# 设置driver路径,这个是我的浏览器路径,要改成你的
location = r'D:\我的程序\360极速\360Chrome\Chrome\Application\360chrome.exe'
# 加载题库
with open('题库.txt','r') as f:
question_data = f.read().split('\n')
# selenium设置与启动
options = webdriver.ChromeOptions()
prefs = {"profile.managed_default_content_settings.images": 2} # 无图模式访问,这样的话加载会快很多
options.add_experimental_option("prefs", prefs)
options.binary_location = location
driver=webdriver.Chrome(chrome_options=options)
driver.get('https://www.2-class.com/competition')
# 等待页面加载完成
time.sleep(5)
# 滑动条事件
def slide_solution(driver):
try:
slide_btn = driver.find_element(by=By.XPATH, value='//*[@id="nc_1_n1z"]')
# 按住滑块按钮
ActionChains(driver).click_and_hold(slide_btn).perform()
# 模拟缓慢的滑动
i = 0
while i <= 420:
time.sleep(0.1)
ActionChains(driver).move_by_offset(20,0).perform()
i += 20
# 释放鼠标
ActionChains(driver).release().perform()
time.sleep(1)
except:
return 0
# 随机选择并构建题目列表
def random_list():
ran = random.sample(range(0, 39),20)
question_list = []
for i in ran:
t = question_data[i].split('-')
question_list.append({"questionId": t[0],"questionContent": t[1]})
return question_list
#模拟登录的事件
def login(account):
# 点击登录按钮
el = driver.find_element(By.XPATH,'/html/body/div/div/div[1]/div/header/div/div[2]/div[2]/div/span/a')
el.click()
time.sleep(2)
# account
el = driver.find_element(By.XPATH,'//*[@id="account"]')
el.send_keys(account)
time.sleep(0.5)
# password
el = driver.find_element(By.XPATH,'//*[@id="password"]')
el.send_keys('a1234567')
time.sleep(0.5)
# 登录
el = driver.find_element(By.CSS_SELECTOR,"[type='submit']")
el.click()
time.sleep(2)
# 如果有滑动条的话
slide_solution(driver)
#cookie和数据
cookie = ''
cookies=driver.get_cookies()
for i in cookies:
cookie = cookie + i['name'] + '=' + i['value'] + ';'
reqtoken = driver.execute_script('return window.__DATA__.reqtoken')
yi_jian_man_fen(cookie,reqtoken,account)
#点击退出
el = driver.find_element(By.XPATH,'//*[@id="app"]/div/div[1]/div/header/div/div[2]/div[2]/div/a')
el.click()
time.sleep(1)
el = driver.find_element(By.XPATH,'//*[@id="app"]/div/div[1]/div/header/div/div[2]/div[2]/div/div/ul/li[6]/a')
el.click()
time.sleep(2)
#开始答题
def yi_jian_man_fen(cookie,reqtoken,account):
print(account+',开始答题')
url = 'https://www.2-class.com/api/quiz/commit'
headers = {
'Cookie': cookie,
'Content-Type': 'application/json',
'User-Agent': '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'
}
time = random.randint(100, 350)
data = {
"list": random_list(),
"time": time,
"reqtoken": reqtoken
}
result = requests.post(url=url, data=json.dumps(data), headers=headers, verify=False)
text = result.text
text = text.split(',')[2]
text = text.split(':')[1]
if text == '100':
text = ',满分!'
print(account,text)
if __name__ == '__main__':
count = 0
accounts = []
with open('账户.txt','r') as f:
accounts = f.read().split('\n')
accounts.remove('')
try:
for account in accounts:
count = count + 1
login(account)
print('已完成'+ str(count) + '个' )
except Exception as e:
re = ''
for i in accounts[count-1:]:
re = re + str(i) + '\n'
with open('账户.txt','w') as f:
f.write(re)
print('程序运行错误:\n' + e)
driver.quit() # 使用完, 记得关闭浏览器, 不然chromedriver.exe进程为一直在内存中.
题库.txt文件
3199-A
3202-D
3203-B
3171-A
3108-C
3141-A
3206-C
3176-C
3147-D
3148-A
3181-B
3217-A
3186-A
3154-C
3155-A
3123-B
3189-C
3159-D
3131-C
3163-B
2986-B
2989-C
2990-D
2959-C
2928-C
2960-A
2961-C
2897-B
2930-D
2898-B
2963-A
2932-D
2901-A
2966-D
2934-C
2904-D
2907-D
2972-C
2973-A
2912-B