//说明使用java的HttpConnection 模拟发送post请求
//该程序用来抓成绩公布网站上的指定范围准考证号的成绩情况
import javaioDataInputStream;
import javaioDataOutputStream;
import javaioInputStream;
import javaioOutputStream;
import HttpURLConnection;
import URL;
import javautilVector;
public class GetMain {
/**
* @param args
*/
private static String URL = ;
private static String url=;
public static void main(String[] args) {
//Post Data 为Form提交的内容
String postData=zkzh=+l+i+j+k+&tijiaox=&tijiaoy=;
String html=GetResponseDataByID(URLpostData);
String[] data=getNeedData(html);
}
}
public static void PrintStrs(String[] str)
{
for(String s:str)
{
Systemoutprint(s+);
}
Systemoutprintln();
}
//通过url和postdata获取返回值该函数为主要函数可以copy使用返回值为一个Html页面的数据
public static String GetResponseDataByID(String urlString postData)
{
String data=null;
try {
URL dataUrl = new URL(url);
HttpURLConnection con = (HttpURLConnection) dataUrlopenConnection();
consetRequestMethod(POST);
consetRequestProperty(ProxyConnection KeepAlive);
consetDoOutput(true);
consetDoInput(true);
OutputStream os=congetOutputStream();
DataOutputStream dos=new DataOutputStream(os);
doswrite(postDatagetBytes());
dosflush();
dosclose();
InputStream is=congetInputStream();
DataInputStream dis=new DataInputStream(is);
byte d[]=new byte[disavailable()];
disread(d);
data=new String(d);
//Systemoutprintln(data);
condisconnect();
} catch (Exception ex) {
exprintStackTrace();
}
return data;
}
/**Get Needed Data Form Responsed Html File**/
static String I=准考证号;
static String I=姓 名;
static String I=级别;
static String I=笔试成绩;
static String I=口试成绩;
public static String[] getNeedData(String html)
{
if(html==null)
return null;
String[] str=new String[];
str[]=getPart(htmlI);
str[]=getPart(htmlI);
str[]=getPart(htmlI);
str[]=getPart(htmlI);
str[]=getPart(htmlI);
return str;
}
public static String getPart(String sourceString type)
{
if(source==null)
return null;
if(sourceindexOf(准考证号输入错误)!=)
return null;
if(sourceindexOf(type)!=)
{
source=sourcesubstring(sourceindexOf(type)+typelength());
source=sourcesubstring(sourceindexOf(</TD></TR>));
source=sourcereplace(</TD> );
source=sourcereplace(<TD> );
source=sourcereplace(<TD align=center > );
source=sourcereplace(<TD align=center> );
source=sourcereplace(\n);
return sourcetrim();
}
else
return null;
}
}