【11.2更新V2.0】第二课堂批量知识竞赛满分
本帖最后由 麦米尔加弗德 于 2022-11-2 18:28 编辑去年的纯后台版挂了,今年发现有nvcVal的验证,还在破解逻辑中...
---
视频教程地址:https://www.bilibili.com/video/BV1VW4y1n7Su/
整合包下载地址: https://pan.baidu.com/s/1EI02F5gSXMMm8_1WW9gD_g 提取码: yzbj
---
2022.11.2 新版本更新
针对一些痛点进行了优化,毕竟没有编程基础的人还是比较多
觉得改动比较多,所以开了一个新帖
地址:https://www.52pojie.cn/thread-1707129-1-1.html
---
2022.10.30 更新 & 答疑
浏览器请使用360极速最新版本(它更新的慢,最新的和我的一样),因为我的selenuim是老版本的,webdriver也是,所以有兼容问题
- 增加了随机选择题库
- 增加了滑动条验证判断(但是不讲武德,我手动滑怎么样都通过不了!!)
- 会检测去掉了账号后的空的一行,防止最后提示运行错误
- 会具体提示现在服务器返回的内容了,而不是凑数的已经完成
- 更多的提示和更多的使用细节
---
# 2022.10.20 警告
被官方发现了,服务器做了策略拦截
存在会被通报的可能,已经有被通报的了,已经完成的不会重做,但是活动结束后会统计一份报告,给到各地做一些内部处理
项目停止维护,就这样吧,请酌情使用!!!!!!!!!!
# 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/div/header/div/div/div/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("")
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/div/header/div/div/div/div/a')
el.click()
time.sleep(1)
el = driver.find_element_by_xpath('//*[@id="app"]/div/div/div/header/div/div/div/div/div/ul/li/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.split('-')
question_list.append({"questionId": t,"questionContent": t})
return question_list
#模拟登录的事件
def login(account):
# 点击登录按钮
el = driver.find_element(By.XPATH,'/html/body/div/div/div/div/header/div/div/div/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,"")
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/div/header/div/div/div/div/a')
el.click()
time.sleep(1)
el = driver.find_element(By.XPATH,'//*[@id="app"]/div/div/div/header/div/div/div/div/div/ul/li/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(',')
text = text.split(':')
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:
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
```
本帖最后由 wsypnet 于 2022-10-19 21:53 编辑
楼主老大,现在自动答题出现 那个 拖动条 如何处理?
就是由于这个拖动条的原因就自动退出了吧? 接下来的想法是解决滑动条问题,然后把代码进行完善,更方便更好用更容易配置,能适应更多的情况
- 自动配置selenuim的驱动
- 不用重置密码,使用xlsx进行导入(虽然不想加模块,但是没办法==)
- 无头模式
- 检验错误并重启自身再次运行
咕咕咕,自己用和给别人 用以及教会别人用真的区别蛮大的 枫止觞 发表于 2022-10-18 19:41
File "C:%users\Administrator\Desktop\PL\pl.py", line 16
driver=webdriver.Chrome(chrome_options ...
driver=webdriver.Chrome(chrome_options=options)
改成
driver=webdriver.Chrome(options=options) fangz110 发表于 2022-10-20 23:16
楼主要是能把账户密码放在一起然后不用统一更改密码就更完美了。(一个一个重置密码太费时了!)
后台统一设置啊,管理员全部设置一样的 xgczwp 发表于 2022-10-21 08:26
能截个图吗,把前面和后面的原来存在的显示出来,加的标红。让我们小白知道具体放在什么地方,谢谢。
#登录
el = driver.find_element(By.CSS_SELECTOR,"")
el.click()
time.sleep(5)
放在下面 lin2509 发表于 2022-10-20 18:49
加了个自动滑验证码,完美解决了!
能分享一下代码吗?谢谢 加了个自动滑验证码,完美解决了!
yuntai 发表于 2022-10-19 06:38
selenium你没安装这个模块 baidu安装方法吧 我搜了好多用pycharm添加的我感觉是这一样 但是 ...
作者用的是selenium 老语法,修改成新的定位语法就可以了。我已经做完了,感谢楼主 jd19960812 发表于 2022-10-19 01:44
E:\PYTHON\JD\Scripts\python.exe C:%users\111\PycharmProjects\pythonProject1\main.py
Traceback (mos ...
打开CMD输入 pip install selenium 安装模块 lin2509 发表于 2022-10-18 22:23
我也没成功
C:%users\Administrator\PycharmProjects\pythonProject1\venv\Scripts\python.exe C:%users\A ...
因为作者用的selenium是老版本,你们用的是刚下载的 用法不一样。 厉害了大佬!
感谢分享,留个标签等待更新,可否添加个自动刷时长功能 感谢,厉害了大佬!
牛逼!!! 感谢分享,非常及时 每年都是要求两个一百,要命啊,手动答题答到吐。 楼主救命,我运行出错了
Warning (from warnings module):
File "C:\Users\Administrator\Desktop\1.py", line 16
driver=webdriver.Chrome(chrome_options=options)
DeprecationWarning: use options instead of chrome_options
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\1.py", line 16, in <module>
driver=webdriver.Chrome(chrome_options=options)
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 69, in __init__
super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 92, in __init__
super().__init__(
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 272, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 364, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 429, in execute
self.error_handler.check_response(response)
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: was killed.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files\Google\Chrome\Application\chromedriver.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
Backtrace:
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
Ordinal0
GetHandleVerifier
GetHandleVerifier
GetHandleVerifier
GetHandleVerifier
Ordinal0
Ordinal0
Ordinal0
Ordinal0
BaseThreadInitThunk
RtlGetAppContainerNamedObjectPath
RtlGetAppContainerNamedObjectPath
感谢分享,非常及时 File "C:\Users\Administrator\Desktop\PL\pl.py", line 16
driver=webdriver.Chrome(chrome_options=options)
DeprecationWarning: use options instead of chrome_options
程序运行错误
老大,这样报错