抓取毛概的题库

抓取毛概的题库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.SAXException;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

//导入马克思的题库,完成时间20118年6月21日晚上九点
public class Demo {
public static void main(String[] args) {
String url = "http://211.67.48.87/wantsMWS/Question.asmx/GetQuestionList?CV=&QStyleCode=DD&QIDList=";
//PD是判断题,DX是单选,DD是多选
int i = 1;
while(i < 100000) {
url += String.valueOf(i)+"&ScreenType=1";
test(url,i);
i++;
url = "http://211.67.48.87/wantsMWS/Question.asmx/GetQuestionList?CV=&QStyleCode=DD&QIDList=";
}


}

static int aaaa=1;
private static void test(String urls, int NO) {
InputStream is = null;
Document document = null;
try {
URL url =
new URL(urls);//如"http://211.67.48.87/wantsMWS/Question.asmx/GetQuestionList?CV=&QStyleCode=DX&QIDList=2158&ScreenType=1"
URLConnection con = url.openConnection();
is = con.getInputStream();
// DOM 解析器
DocumentBuilderFactory domfac = DocumentBuilderFactory.newInstance();
// DOM 工厂获得 DOM 解析器
DocumentBuilder dombuilder = domfac.newDocumentBuilder();
document = dombuilder.parse(is);

} catch (SAXException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();

}
// root要素取得
Element elementRoot = (document).getDocumentElement();
JsonParser parser=new JsonParser();
JsonObject object=(JsonObject)parser.parse(elementRoot.getTextContent().toString());
JsonArray QStyleList = object.get("List").getAsJsonArray();
//------------------------写文件
try
{
String path="C:\\Users\\Administrator\\Desktop\\毛泽东.txt";
File file=new File(path);
if(!file.exists())
file.createNewFile();
FileOutputStream out=new FileOutputStream(file,true); //如果追加方式用true ,非追加用false
for(int i = 0; i < QStyleList.size(); ++i) {
JsonObject item = QStyleList.get(i).getAsJsonObject();
String SubjectCode = item.get("SubjectCode").getAsString(); //试卷类型
String QStyleCode = item.get("QStyleCode").getAsString(); //题目类型
String QID = item.get("QID").getAsString(); //题目ID
String Topic = item.get("Topic").getAsString(); //题干
String IsRTF = item.get("IsRTF").getAsString(); //不知道是啥
JsonArray Option = item.get("OptionList").getAsJsonArray();
//写入文件
StringBuffer sb=new StringBuffer();
sb.append(aaaa+".题干:"+Topic+"\r\n");
System.out.println(SubjectCode);
System.out.println("题干:"+Topic);
for(int j = 0; j < Option.size(); ++j) {
System.out.println("选项"+j+": "+Option.get(j).getAsString());
if(j==0)sb.append("A:"+Option.get(j).getAsString()+"\r\n");
if(j==1)sb.append("B:"+Option.get(j).getAsString()+"\r\n");
if(j==2)sb.append("C:"+Option.get(j).getAsString()+"\r\n");
if(j==3)sb.append("D:"+Option.get(j).getAsString()+"\r\n");
}
String OptionMax = item.get("OptionMax").getAsString();//最大的选项
String OptionType = item.get("OptionType").getAsString(); //选项的类型
String Result = item.get("Result").getAsString(); //答案
System.out.println("答案为:"+Result);

sb.append("答案:"+Result+"\r\n");

if("".equals(Topic)||Topic==null) {
out.close();
System.exit(0);
}

if("MZT".equals(SubjectCode)) {
aaaa++;
out.write(sb.toString().getBytes("utf-8"));//注意需要转换对应的字符集
}



}
out.close();
}
catch(IOException ex)
{
System.out.println(ex.getStackTrace());
}
//----------------------------------写文件
}




}