前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[Python原创] 第二课堂批量知识竞赛满分

[Python原创] 第二课堂批量知识竞赛满分

作者头像
纯情
发布2023-04-27 10:17:59
2960
发布2023-04-27 10:17:59
举报
文章被收录于专栏:纯情博客

这个是python脚本,还有插件版的,有空了会发出来,包括自动登录账号,刷视频课时和练习,知识竞赛,还有普法插件等。

使用步骤

考虑到使用有些复杂,准备出个视频版的教程和资源整合包,比较忙还没录视频,现在就先看着吧.....会用的自己就可以用了 1.安装python 2.安装python运行所需要的模块 3.移动selenium驱动文件到指定地点 4.要登录的账号进行配置

1.安装

python官网下载双击打开,记得勾选path

2.安装模块

用的有两个selenium,requests

3.下载对应浏览器的selenium驱动,放到浏览器目录下

你用的哪个浏览器就放到哪个浏览器下面去

4.要登录的账号进行配置

先去第二课堂把账号密码列表下载下来,是excel的 然后把账号密码放到python文件夹下的 账户.txt 文件夹里面

最后点击运行即可

全部代码如下

代码语言:javascript
复制
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进程为一直在内存中.
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-10-18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 使用步骤
  • 1.安装
  • 2.安装模块
  • 3.下载对应浏览器的selenium驱动,放到浏览器目录下
  • 4.要登录的账号进行配置
  • 最后点击运行即可
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档