PostMethod獲取post提交的頁面代碼
http://lsg.cnki.net/grid20/Brief.aspx?ID=1&classtype=&systemno=&NaviDatabaseName=&NaviField=
這個是中國期刊網的檢索請求,我現在需要通過這個來獲取檢索出來的信息,解決方法已經有了,就是得不到檢索信息,查詢內容是空的。
應該是少add了一些檢索所需內容。
下面是我的代碼
哪位大哥幫幫忙,解決下
這個是中國期刊網的檢索請求,我現在需要通過這個來獲取檢索出來的信息,解決方法已經有了,就是得不到檢索信息,查詢內容是空的。
應該是少add了一些檢索所需內容。
下面是我的代碼
1
import java.io.IOException;
2
import java.util.Calendar;
3
import java.util.GregorianCalendar;
4
import org.apache.commons.httpclient.HttpClient;
5
import org.apache.commons.httpclient.HttpException;
6
import org.apache.commons.httpclient.HttpStatus;
7
import org.apache.commons.httpclient.methods.PostMethod;
8
9
10
public class PostTest {
11
12
public static void main(String[] args){
13
14
PostMethod postMethod = new PostMethod("http://lsg.cnki.net/grid20/Brief.aspx?ID=1&classtype=&systemno=&NaviDatabaseName=&NaviField=");
15
postMethod.addParameter("advancedvalue1","java");
16
postMethod.addParameter("advancedfield1","主題");
17
postMethod.addParameter("yearstart","1979");
18
postMethod.addParameter("yearend",String.valueOf(GregorianCalendar.getInstance().get(Calendar.YEAR)));
19
postMethod.addParameter("RecordsPerPage","20");
20
postMethod.addParameter("SearchRange","All");
21
postMethod.addParameter("searchmatch","0");
22
postMethod.addParameter("order","dec");
23
postMethod.addParameter("display","chinese");
24
postMethod.addParameter("NaviDatabaseName","ZJCLS");
25
postMethod.addParameter("encode","gb");
26
postMethod.addParameter("VarNum","1");
27
postMethod.addParameter("singleleafcode","J");
28
postMethod.addParameter("strNavigatorName",",A,B,C,D,E,F,G,H,I,J");
29
postMethod.addParameter("strNavigatorValue",",理工A(數學物理力學天地生),理工B(化學化工冶金環境礦業),理工C(機電航空交通水利建筑能源),農業,醫藥衛生,文史哲,政治軍事與法律,教育與社會科學綜合,電子技術及信息科學,經濟與管理");
30
HttpClient client = new HttpClient();
31
client.setConnectionTimeout(1000 * 60);
32
int status=0;
33
try {
34
status = client.executeMethod(postMethod);
35
} catch (HttpException e) {
36
// TODO Auto-generated catch block
37
e.printStackTrace();
38
} catch (IOException e) {
39
// TODO Auto-generated catch block
40
e.printStackTrace();
41
}
42
if(status==HttpStatus.SC_OK) {
43
makeResponseObject(postMethod.getResponseBodyAsString());
44
} else {
45
}
46
postMethod.releaseConnection();
47
48
}
49
// 根據HTTP請求后返回的字串生成結果封裝類的實例
50
private static void makeResponseObject(String sResponse) {
51
System.out.println("-------------------"+sResponse);
52
System.out.println("-------------------");
53
String 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>";
54
String 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>";
55
String 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

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

哪位大哥幫幫忙,解決下
posted @ 2008-06-16 10:25 迷失的風 閱讀(3261) | 評論 (1) | 編輯 收藏