迷失的風(fēng)

          就這樣活著
          隨筆 - 1, 文章 - 1, 評(píng)論 - 1, 引用 - 0
          數(shù)據(jù)加載中……

          PostMethod獲取post提交的頁面代碼

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

          這個(gè)是中國期刊網(wǎng)的檢索請求,我現(xiàn)在需要通過這個(gè)來獲取檢索出來的信息,解決方法已經(jīng)有了,就是得不到檢索信息,查詢內(nèi)容是空的。
          應(yīng)該是少add了一些檢索所需內(nèi)容。

          下面是我的代碼
           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(數(shù)學(xué)物理力學(xué)天地生),理工B(化學(xué)化工冶金環(huán)境礦業(yè)),理工C(機(jī)電航空交通水利建筑能源),農(nóng)業(yè),醫(yī)藥衛(wèi)生,文史哲,政治軍事與法律,教育與社會(huì)科學(xué)綜合,電子技術(shù)及信息科學(xué),經(jīng)濟(jì)與管理"); 
          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// 根據(jù)HTTP請求后返回的字串生成結(jié)果封裝類的實(shí)例 
          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 on 2008-06-16 10:25 迷失的風(fēng) 閱讀(3262) 評(píng)論(1)  編輯  收藏

          評(píng)論

          # re: PostMethod獲取post提交的頁面代碼[未登錄]  回復(fù)  更多評(píng)論   

          用NameValuePair[] data = { new NameValuePair("id", "youUserName"),new NameValuePair("passwd", "yourPwd") };這種方式傳參數(shù)試試,先確定你是不是post了所有必需的參數(shù),然后再檢查獲取到的數(shù)據(jù)。
          2008-06-21 22:52 | Chris

          只有注冊用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 石河子市| 汝城县| 古蔺县| 镇雄县| 逊克县| 综艺| 昌邑市| 民丰县| 宜兴市| 洮南市| 逊克县| 长岭县| 无为县| 铁岭市| 扬中市| 静乐县| 布尔津县| 合阳县| 乐都县| 和平县| 武隆县| 如东县| 达日县| 凤山县| 晋中市| 亚东县| 抚远县| 个旧市| 宁城县| 瑞丽市| 永济市| 东安县| 兰州市| 武平县| 剑川县| 阿图什市| 石景山区| 嘉荫县| 德惠市| 梨树县| 方山县|