Re: [討論] 給阿pu看的 XD

看板bioinfo_lab作者 (喝杯JAVA)時間18年前 (2006/01/20 21:31), 編輯推噓1(102)
留言3則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《agomi (萊姆酒)》之銘言: : 在我們使用post方法的時候 : 因為網頁會跟我們要資料 所以要回傳資料給她們 : 在httpclient裡面用的是NameValuePair這個方法 : 以我同學的mail server為例 : http://mail.formula7.idv.tw : 我所準備的NameValuePair有下面這幾個 : NameValuePair action = new NameValuePair("action", "/cgi-bin/openwebmail/openwebmail.pl"); : NameValuePair userid = new NameValuePair("loginname", "我同學的帳號名稱"); : NameValuePair password = new NameValuePair("password", "我同學的密碼"); : NameValuePair login = new NameValuePair("logindomain", "mail.formula7.idv.tw"); : 我跟同學討論之後 他告訴我 我要注意每個具有<input>的標籤 : ex. <Input type = "text" name="loginname" ... OOXX ... > : 因為每個input都可能是網頁要求的參數 如果網頁沒有要到參數 開網頁就會失敗 : 問題是檢視原始碼的時候 可能有10個input標籤 : 但是我不知道網頁其實需要幾個輸入的參數 : 像上面這四個NameValuePair好像也是試誤法猜出來的 : 我如果只寫前面三個好像也可以跑出一樣的結果 : 不管怎樣 我已經可以用PostMethod把這些名值對傳入網頁 順利通過認證 : 而且我家遠端桌面台大很慢 (web of knowledge要台大ip才能開) : 所以我想先試試看對google作search動作 : 我的想法是google只有一個輸入欄位 : 所以我只準備一個NameValuePair : 寫成 NameValuePair search = new NameValuePair( "hl", "Agomi" ) ; : 表示我想在google上查詢Agomi : 但是傳回的statuscode是501 Google是用get方式傳資料 應該是用了post方式才會出現這樣錯誤 只不過我試了一下用get方式傳,似乎抓不到資料 : 內容是: : 10.5.2 501 Not Implemented : The server does not support the functionality required to fulfill the request. : This is the appropriate response when the server does not recognize the request : method and is not capable of supporting it for any resource. : google的原始碼中還有很多組input標籤 : 但是我看不出我該怎麼選擇 : 而且如果每次都要這樣猜 好像很不合理 ? : 如果有10個input標籤 : 那可是有10!種組合 : 所以我這邊的問題就是... : 有沒有更好的方法看出我們需要準備幾組NameValuePair來餵給網頁 ? : 有沒有辦法得知網頁需要幾個input parameter ? : 大家來討論看看吧 :) : 我想如果你還沒看到這邊 我上面寫的東西也可以算是我前鎮子的心得 :) 今天有一點點小小進展...可以抓到前十筆的snippet了 只是getPostMethod裡的SID的值要先上網做查詢動作檢示原始碼 看新的SID碼是什麼,替換新的就可以抓到資料了... 還有一點就是網頁不能關掉 裡面還有一些額外程式碼是自動抓SID的... 先用get抓到SID,再用post方式把SID傳過去 不過沒有成功...等我試好了再po上來了... ----------------------------------------------------- package httpclient; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpMethod; import org.apache.commons.httpclient.methods.GetMethod; import java.io.*; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.PostMethod; /** * <p>Title: </p> * * <p>Description: </p> * * <p>Copyright: Copyright (c) 2006</p> * * <p>Company: </p> * * @author not attributable * @version 1.0 */ public class ISI { public static void main(String[] args) { ISI isi = new ISI(); HttpClient client = new HttpClient(); HttpMethod method = null; /*String SIDHtmlContent = isi.getSIDHTMLContent(client,method); Session session = new Session(); session.setCandidate(SIDHtmlContent); session.setRegex("SID=.*&Fun"); String SID = session.getSID(); String finalSID = session.normalizeSID(SID); */ client.getHostConfiguration().setHost("xs17.isiknowledge.com",80,"http"); method = isi.getPostMethod("finalSID"); try { client.executeMethod(method); System.out.println(method.getResponseBodyAsString()); } catch (IOException ex) { } method.releaseConnection(); } public String getSIDHTMLContent(HttpClient client,HttpMethod method) { String content = ""; method = new GetMethod("http://portal.isiknowledge.com/portal.cgi"); try { client.executeMethod(method); System.out.println(method.getStatusLine()); content = method.getResponseBodyAsString(); } catch (IOException ex) { } finally { //method.releaseConnection(); } return content; } private HttpMethod getPostMethod(String strSID){ PostMethod post = new PostMethod("/CIW.cgi"); NameValuePair Form = new NameValuePair("Form","HomePage"); NameValuePair Func = new NameValuePair("Func","Search"); NameValuePair SID = new NameValuePair("SID","C2L9BKp683@poBieCPd"); NameValuePair topic = new NameValuePair("topic","nod2"); post.setRequestBody(new NameValuePair[] { Form,Func,SID,topic}); return post; } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.137.133 ※ 編輯: aadean 來自: 140.112.137.133 (01/20 21:48)

01/21 10:23, , 1F
我昨天看你的jsp2.0技術手冊上面有寫到有個jsp指令可以抓到
01/21 10:23, 1F

01/21 10:23, , 2F
session id 而且自動加入網址之後回傳出來 但不知道httpclie
01/21 10:23, 2F

01/21 10:24, , 3F
有沒有類似的方法
01/21 10:24, 3F
文章代碼(AID): #13qEPD-p (bioinfo_lab)
討論串 (同標題文章)
文章代碼(AID): #13qEPD-p (bioinfo_lab)