0 Unstar Star 0 Fork 0

Tim / spider_xpuJava

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
西安工程大学正方教务爬虫(目前可爬取个人信息与课表),根据文档配置URL,则其它学校的正方教务系统也可以使用此爬虫,注意此爬虫是基于Java的。 spread retract

Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
Readme.md

1、引入依赖

<dependencies>
    <dependency>
        <groupId>com.gitee.zouchanglin</groupId>
        <artifactId>spider_xpu</artifactId>
        <version>1.1</version>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

2、使用示例

import cn.zouchanglin.spider_xpu.SpiderResult;
import cn.zouchanglin.spider_xpu.cache.ResultCache;
import cn.zouchanglin.spider_xpu.core.SpiderCore;

import javax.security.auth.login.LoginException;
import java.awt.*;
import java.net.URI;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        // Key就是一个标识用户唯一的键(如可以传OpenId、UnionId、学号、身份证号等)
        String key = "123456789";
        String userId = "";
        String passsword = "";

        // 1、获取验证码URL
        String url = SpiderCore.getCheckCodeUrl(key);

        // 打开浏览器并输入验证码
        Desktop desktop = Desktop.getDesktop();
        if (Desktop.isDesktopSupported() && desktop.isSupported(Desktop.Action.BROWSE)) {
            URI uri = new URI(url);
            desktop.browse(uri);
        }
        Scanner scanner = new Scanner(System.in);
        String code = scanner.nextLine();

        // 记录用时
        long millis = System.currentTimeMillis();
        SpiderResult spiderResult = null;
        try {
            // 2、获取同步调用结果只返回用户信息 + 当前学年的课表
            spiderResult = SpiderCore.go(userId, password, code, key);
        }catch (LoginException e){
            // 登录失败
            System.out.println(e.toString());
        }
        // 同步调用结果
        System.out.println("同步调用只返回用户信息+当前学年的课表:" + spiderResult);
        System.out.println("执行耗时:" + (System.currentTimeMillis() - millis));

        // 阻塞等待缓存池中存在结果对象
        while(!ResultCache.SPIDER_RESULT_CACHE.containsKey(key));

        // 取出缓存池中的结果
        SpiderResult result = ResultCache.SPIDER_RESULT_CACHE.get(key);
        System.out.println(result);

        //TODO 持久化
        System.out.println("完成持久化....");

        // 从缓存池中移除结果对象
        ResultCache.SPIDER_RESULT_CACHE.remove(key);
    }
}

Comments ( 0 )

Sign in for post a comment

Java
1
https://gitee.com/zouchanglin/spider_xpu.git
git@gitee.com:zouchanglin/spider_xpu.git
zouchanglin
spider_xpu
spider_xpu
master

Search

132457 8cb2edc1 1899542 131848 70c8d3a4 1899542