Re: [問題]如何使用J2SE去網頁自動填表單?

看板java作者 (訓練自己的耐性吧)時間19年前 (2006/04/24 21:07), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串3/5 (看更多)
※ 引述《lovepc (期待畢業~)》之銘言: ---------------------------------------------- 我後來解決了 , [法1] 使用GET: 靠的是把參數加在網址後面~~~ ^^^^ 1.先把網頁的post , 改成get 來開啟... 2.選擇好自己要的選項和資料 3.按submit , copy 下一頁出現的網址 4.根據此網址參數內容 ,改成由java 輸出即可 EX: String QueryStr = "網址?參數=value&..."; URLConnection connection = new URL(QueryStr).openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader (connection.getInputStream())); // 印出 http server 傳回的buffer內容 String line ; while( (line = in.readLine()) != null) System.out.println(line); ***************************************************** [法2] 使用POST : 使用 org.apache.commons.httpclient ^^^^^ 下載: http://jakarta.apache.org/site/downloads/downloads_commons.html 另外也需要其他幾個 jar , EX:commons-logging , commons-codec EX: HttpClient httpclient = new HttpClient(); PostMethod post = new PostMethod( your_URI); NameValuePair[] data = { new NameValuePair("organism", "S. cerevisiae"), . . . //設定你要的參數 }; post.setRequestBody(data); httpclient.executeMethod(post); BufferedReader in = new BufferedReader (new InputStreamReader( post.getResponseBodyAsStream())); // 底下自行處理 內容 大概這樣~~~~~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.186.203 ※ 編輯: lovepc 來自: 140.113.186.203 (04/23 20:40) ※ 編輯: lovepc 來自: 140.113.166.162 (04/24 21:06) -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.113.166.162 ※ 編輯: lovepc 來自: 140.113.166.162 (04/24 21:10)

04/24 21:47, , 1F
==.== 寫好少... 多寫一點嘛... [淚奔]
04/24 21:47, 1F
※ 編輯: lovepc 來自: 140.113.186.203 (04/24 21:58) ※ 編輯: lovepc 來自: 140.113.186.203 (04/24 21:59) ※ 編輯: lovepc 來自: 140.113.186.203 (04/24 22:00)
文章代碼(AID): #14JCrqUA (java)
文章代碼(AID): #14JCrqUA (java)