迷失的风

就这样活着
随笔 - 1, 文章 - 1, 评论 - 1, 引用 - 0
数据加载中……

2008年6月16日

PostMethod获取post提交的页面代码

http://lsg.cnki.net/grid20/Brief.aspx?ID=1&classtype=&systemno=&NaviDatabaseName=&NaviField=

这个是中国期刊网的检索请求,我现在需要通过这个来获取检索出来的信息,解决方法已经有了,就是得不到检索信息,查询内容是空的。
应该是少add了一些检索所需内容。

下面是我的代码
 1import java.io.IOException; 
 2import java.util.Calendar; 
 3import java.util.GregorianCalendar; 
 4import org.apache.commons.httpclient.HttpClient; 
 5import org.apache.commons.httpclient.HttpException; 
 6import org.apache.commons.httpclient.HttpStatus; 
 7import org.apache.commons.httpclient.methods.PostMethod; 
 8
 9
10public class PostTest 
11
12public static void main(String[] args)
13
14PostMethod postMethod = new PostMethod("http://lsg.cnki.net/grid20/Brief.aspx?ID=1&classtype=&systemno=&NaviDatabaseName=&NaviField="); 
15postMethod.addParameter("advancedvalue1","java"); 
16postMethod.addParameter("advancedfield1","主题"); 
17postMethod.addParameter("yearstart","1979"); 
18postMethod.addParameter("yearend",String.valueOf(GregorianCalendar.getInstance().get(Calendar.YEAR))); 
19postMethod.addParameter("RecordsPerPage","20"); 
20postMethod.addParameter("SearchRange","All"); 
21postMethod.addParameter("searchmatch","0"); 
22postMethod.addParameter("order","dec"); 
23postMethod.addParameter("display","chinese"); 
24postMethod.addParameter("NaviDatabaseName","ZJCLS"); 
25postMethod.addParameter("encode","gb"); 
26postMethod.addParameter("VarNum","1"); 
27postMethod.addParameter("singleleafcode","J"); 
28postMethod.addParameter("strNavigatorName",",A,B,C,D,E,F,G,H,I,J"); 
29postMethod.addParameter("strNavigatorValue",",理工A(数学物理力学天地生),理工B(化学化工冶金环境矿业),理工C(机电航空交通水利建筑能源),农业,医药卫生,文史哲,政治军事与法律,教育与社会科学综合,电子技术及信息科学,经济与管理"); 
30HttpClient client = new HttpClient(); 
31client.setConnectionTimeout(1000 * 60); 
32int status=0
33try 
34status = client.executeMethod(postMethod); 
35}
 catch (HttpException e) 
36// TODO Auto-generated catch block 
37e.printStackTrace(); 
38}
 catch (IOException e) 
39// TODO Auto-generated catch block 
40e.printStackTrace(); 
41}
 
42if(status==HttpStatus.SC_OK) 
43makeResponseObject(postMethod.getResponseBodyAsString()); 
44}
 else 
45}
 
46postMethod.releaseConnection(); 
47
48}
 
49// 根据HTTP请求后返回的字串生成结果封装类的实例 
50private static void makeResponseObject(String sResponse) 
51System.out.println("-------------------"+sResponse); 
52System.out.println("-------------------"); 
53String regExNums = "<TD\\s*style=\"FONT-SIZE:\\s*9pt;\\s*COLOR:\\s*#000000;\\s*WORD-WRAP:\\s*break-word\"\\s*vAlign=center\\s*bgColor=#f4f5f6\\s*height=30>\\s*共有记录\\s*(\\d+)\\s*条\\s* \\s*</TD>"
54String regExData = "<TR>\\s*<TD\\s*style=\"FONT-SIZE:\\s*9pt;\\s*WORD-WRAP:\\s*break-word\"\\s*(?:align=left)?\\s*bgColor=#\\S+\\s*>([\\s\\S]*?)</TR>"
55String regExPage = "<TD\\s*style=\"FONT-SIZE:\\s*9pt;\\s*COLOR:\\s*#000000;\\s*WORD-WRAP:\\s*break-word\"\\s*vAlign=center\\s*bgColor=#f4f5f6\\s*height=30>\\s*<A\\s*href=\"(.*)\">(?:上页|下页)</A>"
56}
 
57
58}
 
59

哪位大哥帮帮忙,解决下

posted @ 2008-06-16 10:25 迷失的风 阅读(3245) | 评论 (1)编辑 收藏