• 大小: 2.02MB
    文件类型: .zip
    金币: 2
    下载: 0 次
    发布日期: 2024-01-28
  • 语言: Python
  • 标签:

资源简介

中国科学院大学教务抢课程序 多线程暴力版

资源截图

代码片段和文件信息

#!/usr/bin/python2.7
# -*- coding: utf-8 -*-
# Author: Hurray(hurray0@icloud.com)
# Date: 2017.06.02 17:25:05

import sys
import re
import time
import json
import threading
from threading import Thread Lock
import cookielib
import urllib
import urllib2

reload(sys)
sys.setdefaultencoding(‘utf8‘)


class Spider():
    “““爬虫通用类“““

    def __init__(self):
        self.cookie = cookielib.MozillaCookieJar(““)
        self.header = [(
            ‘User-agent‘
            ‘Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/602.2.14 (KHTML like Gecko) Version/10.0.1 Safari/602.2.14‘
        ) (‘DNT‘ ‘1‘) (‘Accept‘ ‘*/*‘) (‘X-Requested-With‘
                                             ‘xmlHttpRequest‘)]
        handler = urllib2.HTTPCookieProcessor(self.cookie)
        self.opener = urllib2.build_opener(handler)
        self.opener.addheaders = self.header

    def open(self url *postData):
        “““获取网页并添加/修改新的cookie到self.opener“““
        if len(postData) == 0:
            response = self.opener.open(url)
        else:
            data = urllib.urlencode(postData[0])
            response = self.opener.open(url data)
        self.doc = response.read()

    def get(self url data):
        “““发送get消息“““
        textmod = urllib.urlencode(data)
        req = urllib2.Request(url=‘%s%s%s‘ % (url ‘?‘ textmod))
        self.open(req)

    def post(self url data):
        “““发送post消息“““
        self.open(url data)


class UCAS():
    “““UCAS教务处抢课实现类“““

    def __init__(self course username password):
        self.course = course
        self.username = username
        self.password = password
        self.lock = Lock()
        self.threadNum = 0
        self.errInfo = ““

    def __getThreadNum(self):
        “““原子变量threadNum读操作“““
        self.lock.acquire()
        result = self.threadNum
        self.lock.release()
        return result

    def __addThreadNum(self):
        “““原子变量threadNum加操作“““
        self.lock.acquire()
        self.threadNum += 1
        self.lock.release()

    def __reduceThreadNum(self):
        “““原子变量threadNum减操作“““
        self.lock.acquire()
        self.threadNum -= 1
        self.lock.release()

    def getReady(self):
        “““一些准备工作,提取cookie等“““
        data = {
            ‘username‘: self.username
            ‘password‘: self.password
            ‘remember‘: ‘checked‘
        }
        data2 = “deptIds=910&deptIds=911&deptIds=957&deptIds=912&deptIds=928&deptIds=913&deptIds=914&deptIds=921&deptIds=951&deptIds=952&deptIds=958&deptIds=917&deptIds=945&deptIds=927&deptIds=964&deptIds=915&deptIds=954&deptIds=955&deptIds=959&deptIds=946&deptIds=961&deptIds=962&deptIds=963&sb=0“
        data3 = “deptIds=910&deptIds=911&deptIds=957&deptIds=912&deptIds=928&deptIds=913&deptIds=914&deptIds=921&deptIds=951&deptIds=952&deptIds=958&deptIds=917&deptIds=945&deptIds=927&deptIds=964&deptIds=915&deptIds=954&deptIds=955&deptIds=959&deptIds=946&deptIds=961&deptIds=962&deptIds=963“
        url1 = “http://o

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-06-05 04:41  UCAS_GET_Course-master\
     文件         731  2017-06-05 04:41  UCAS_GET_Course-master\README.md
     目录           0  2017-06-05 04:41  UCAS_GET_Course-master\img\
     文件      789963  2017-06-05 04:41  UCAS_GET_Course-master\img\Snip20170602_15.png
     文件      226552  2017-06-05 04:41  UCAS_GET_Course-master\img\Snip20170602_16.png
     文件       71859  2017-06-05 04:41  UCAS_GET_Course-master\img\Snip20170602_17.png
     文件     1022863  2017-06-05 04:41  UCAS_GET_Course-master\img\Snip20170605_4.png
     文件        8647  2017-06-05 04:41  UCAS_GET_Course-master\ucas.py

评论

共有 条评论