# spider_xpu
**Repository Path**: zouchanglin/spider_xpu
## Basic Information
- **Project Name**: spider_xpu
- **Description**: 西安工程大学正方教务爬虫(目前可爬取个人信息与课表),根据文档配置URL,则其它学校的正方教务系统也可以使用此爬虫,注意此爬虫是基于Java的。
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 1
- **Forks**: 1
- **Created**: 2020-09-11
- **Last Updated**: 2022-05-11
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
1、引入依赖
```xml
com.gitee.zouchanglin
spider_xpu
1.1
jitpack.io
https://jitpack.io
```
2、使用示例
```java
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);
}
}
```