//說明使用java的HttpConnection 模擬發送post請求
//該程序用來抓成績公布網站上的指定范圍准考證號的成績情況
import java
import java
import java
import java
import
import
import java
public class GetMain {
/**
* @param args
*/
private static String URL =
private static String url
public static void main(String[] args) {
//Post Data 為Form提交的內容
String postData=
String html=GetResponseDataByID(URL
String[] data=getNeedData(html);
}
}
public static void PrintStrs(String[] str)
{
for(String s:str)
{
System
}
System
}
//通過url和postdata獲取返回值
public static String GetResponseDataByID(String url
{
String data=null;
try {
URL dataUrl = new URL(url);
HttpURLConnection con = (HttpURLConnection) dataUrl
con
con
con
con
OutputStream os=con
DataOutputStream dos=new DataOutputStream(os);
dos
dos
dos
InputStream is=con
DataInputStream dis=new DataInputStream(is);
byte d[]=new byte[dis
dis
data=new String(d);
//System
con
} catch (Exception ex) {
ex
}
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[
str[
str[
str[
str[
return str;
}
public static String getPart(String source
{
if(source==null)
return null;
if(source
return null;
if(source
{
source=source
source=source
source=source
source=source
source=source
source=source
source=source
return source
}
else
return null;
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25779.html