JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java 程式分享區 » Web  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友    訂閱主題
reply to topicthreaded modego to previous topicgo to next topic
話題被移動
該話題已被移動 - browser , 2004-02-25 11:59
如果您尚不清楚該話題被移動的原因,請參考論壇規則以及本版公告或者聯系本版版主。
本主題所含的標籤
無標籤
作者 [JSP]擷取網頁 [精華]
karr1234





發文: 8
積分: 1
於 2004-02-25 01:24 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
感謝之前各位的幫忙,程式算是完成了,
在此po出來貢獻給需要的人…
本程式主要是將使用者需入的keyword送給google再將其結果回存成txt
也就是其html內容,需要注意的部分如下標^^^^處。
1
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
<% 
String sCurrentLine; 
 
String sTotalString; 
 
String urlstring="";
String keyword = new String( request.getParameter("query").getBytes("ISO-8859-1"),"big5" );
 
urlstring="http://www.google.com/search?q=" + keyword + "&ie=Big5&hl=zh-TW&lr=&inlang=zh-TW&lr=";   
 
String get="";
 
sCurrentLine=""; 
 
sTotalString=""; 
 
URL l_url = new URL( urlstring ); 
 
URLConnection l_connection = l_url.openConnection();
 
l_connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)");
//^^^^^^^^^^^^^^^^^^^^^一定要設,否則無法執行
 
BufferedReader l_reader = new BufferedReader(new InputStreamReader(l_connection.getInputStream())); 
 
while ((sCurrentLine = l_reader.readLine()) != null) 
{ 
sTotalString+=sCurrentLine+"\r\n";
} 
 
String path = request.getRealPath("/");
path=path+"Test.txt";
FileWriter ow = new FileWriter(path);
ow.write(sTotalString);
ow.close();    
 
%> 


caterpillar edited on 2005-02-21 17:32
reply to postreply to post
作者 Re:[教學]擷取網頁 [Re:karr1234]
weaker

小屁屁∼



發文: 379
積分: 4
於 2004-02-25 01:38 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
karr1234 wrote:
感謝之前各位的幫忙,程式算是完成了,
在此po出來貢獻給需要的人…
本程式主要是將使用者需入的keyword送給google再將其結果回存成txt
也就是其html內容,需要注意的部分如下標^^^^處。
1
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
<% 
String sCurrentLine; 
 
String sTotalString; 
 
String urlstring="";
String keyword = new String( request.getParameter("query").getBytes("ISO-8859-1"),"big5" );
 
urlstring="http://www.google.com/search?q=" + keyword + "&ie=Big5&hl=zh-TW&lr=&inlang=zh-TW&lr=";   
 
String get="";
 
sCurrentLine=""; 
 
sTotalString=""; 
 
URL l_url = new URL( urlstring ); 
 
URLConnection l_connection = l_url.openConnection();
 
l_connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)");
//^^^^^^^^^^^^^^^^^^^^^一定要設,否則無法執行
 
BufferedReader l_reader = new BufferedReader(new InputStreamReader(l_connection.getInputStream())); 
 
while ((sCurrentLine = l_reader.readLine()) != null) 
{ 
sTotalString+=sCurrentLine+"\r\n";
} 
 
String path = request.getRealPath("/");
path=path+"Test.txt";
FileWriter ow = new FileWriter(path);
ow.write(sTotalString);
ow.close();    
 
%> 


既然是 html 內容,為何不存成 .html?


reply to postreply to post
作者 Re:[教學]擷取網頁 [Re:karr1234]
karr1234





發文: 8
積分: 1
於 2004-02-25 09:15 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
如果你需要的話,存成html檔也是可以的。
我的目的是擷取html的標韱內容做分析,
所以存成txt。


reply to postreply to post
作者 Re:[JSP]擷取網頁 [Re:karr1234]
rpg36000





發文: 1
積分: 0
於 2004-04-05 21:33 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
感謝 ! 正好需要這樣的偽裝機制 ............

你應該也是做 text mining 的吧 ?


reply to postreply to post
作者 Re:[JSP]擷取網頁 [Re:karr1234]
lanslor





發文: 2
積分: 0
於 2004-07-22 18:22 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問一下各位前輩...
我套用了karr大大的程式
測試的結果卻出現了亂碼
是我哪裡需要再設定呢?
感謝您的回覆~~^^


lanslor edited on 2004-07-22 19:55
reply to postreply to post
作者 Re:[JSP]擷取網頁 [Re:karr1234]
lanslor





發文: 2
積分: 0
於 2004-07-23 18:37 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
解決了@@
我之前是使用post方法傳遞值
用get之後就ok了~~Smile


lanslor edited on 2004-07-24 17:40
reply to postreply to post
作者 Re:[JSP]擷取網頁 [Re:karr1234]
xigua





發文: 1
積分: 0
於 2004-07-27 04:12 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
By using JSTL, it would be much simpler.
<c:set var="searchResult">
<c:import url="someurl"/>
</c:set>

After that, you can use FileWriter to write the resultstring to a txt file. Or, you can make use of apache.jakarta.taglibs.regexp to find whatever you want in the resultstring in the same jsp file.

Good Luck.
XiGuA


reply to postreply to post
作者 Re:[JSP]擷取網頁 [Re:karr1234]
Maxyang





發文: 5
積分: 0
於 2004-10-03 19:28 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
我觉得这样更方便:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public String getDocumentAt(String urlString) {
 StringBuffer document = new StringBuffer();
 try {
  URL url = new URL(urlString);
  URLConnection conn = url.openConnection();
  BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
  String line = null;
  while ((line = reader.readLine()) != null)
   document.append(line + "\n");
   reader.close();
 } catch (MalformedURLException e) {
  System.out.println("Unable to connect to URL: " + urlString);
 } catch (IOException e) {
  System.out.println("IOException when connecting to URL: " + urlString);
 }
 return document.toString();
}


browser edited on 2004-10-04 00:48
reply to postreply to post
作者 Re:[JSP]擷取網頁 [Re:karr1234]
pllo10799





發文: 2
積分: 0
於 2005-10-14 11:15 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
SmileSmile不好意思.. 沾了大大的光....
小弟在寫JSP的時候,也是在收變數的時候
一樣會有亂碼發生..
後來看到大大這一段 code

String keyword = new String( request.getParameter("query").getBytes("ISO-8859-1"),"big5" );

小弟用在自己的JSP上..JSP沒有亂碼的問題了..
資料庫也沒有亂碼的問題.
真是非常感謝..


reply to postreply to post
» JWorld@TW »  Java 程式分享區 » Web

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8