作者 |
保存论坛所有贴子的算法,并附上JAVA程序 |
|
言轻 [博客] [个人文集]
头衔: 海归中校 声望: 学员
加入时间: 2004/03/13 文章: 137
海归分: 42923
|
|
作者:言轻 在 海归商务 发贴, 来自【海归网】 http://www.haiguinet.com
声明1:刚才有幸读到ARTHUR的“再上一次,希望不要被删”的帖子,对ARTHUR的立场非常理解,并因此对ARTHUR非常尊敬。提供JAVA程序,不是和ARTHUR作对,只是希望,能够保留下海归论坛网友的辛勤耕耘的成果。
声明2:所附内容,仅供海归论坛的技术人员参考,本人不拥有版权,但也不对可能造成的数据损失承担任何责任。
============================
诚如自由原子弹兄所言,丢失了这里的贴子挺可惜的。
我曾以写程序为生,以下为主要算法,任何系统管理员花上几个小时,可以从任何能上网的WINDOWS或UNIX/LINUX终端,将论坛所有信息(比如主贴顺序版)全部记录下来。(如果有错误,还恳请技术人员,包括AUTHER,多加斧正。)
以下为步骤梗概。
[1] 列出到今日(2004年2月3日)为止的76页主贴顺序版。
这些网页的地址很有规律:https://www.haiguinet.com/Haigui.asp?ID=4&Page=2
这是76页中的第2页,其他依此类推。
[2] 使用可以从命令行启动的程序(比如一个SCRIPT命令程序),将76页内容截取下来。
几年以前有个常用程序叫WINGET,系统管理员一定都熟悉。
本文末尾附了一个JAVA程序,版权归OREILLEY及DAVID FALANAGAN所有。
使用WINGET的好处是,不需要编译JAVA程序。但是需要去下载WINGET,我已经不记得在哪里了。
如果使用所附JAVA程序,基本步骤如下(不一定100%准确):
[2.0] 设置Sun Microsystems的Java环境,如CLASSPATH等。 [2.1] 将这个程序置于myFolder/com/davidflanagan/examples/net目录下。 [2.2] 转往myFolder/com/davidflanagan/examples/net,编译:javac GetURL.java [2.3] 转往myFolder,运行(所有内容都在同一行上): java com.davidflanagan.examples.net.GetURL "https://www.haiguinet.com/Haigui.asp?ID=4&Page=2" myPage2.html
[3] 从76页下载完成的主贴顺序网页中,提取出贴子的链接。
比如可以用Unix上的grep工具,现在的Java编程也已经支持这个功能。
具体命令类似于:
grep myPage2.html,这里可以用"href","TxtFile",等等。
本步骤执行的结果是,将所有网友的帖子全部搜集在一起,并可以将其存放在某个文件中,比如all_posts.list.
[4] 使用GetURL程序(或WINGET之类),通过一个SCRIPT,逐一将网友的帖子下载完毕。
附录:
用GET仪式获取网页信息的JAVA 程序
/* * Copyright (c) 2000 David Flanagan. All rights reserved. * This code is from the book Java Examples in a Nutshell, 2nd Edition. * It is provided AS-IS, WITHOUT ANY WARRANTY either expressed or implied. * You may study, use, and modify it for any non-commercial purpose. * You may distribute it non-commercially as long as you retain this notice. * For a commercial use license, or to purchase the book (recommended), * visit https://www.davidflanagan.com/javaexamples2. */
package com.davidflanagan.examples.net; import java.io.*; import java.net.*;
/** * This simple program uses the URL class and its openStream() method to * download the contents of a URL and copy them to a file or to the console. **/ public class GetURL { public static void main(String[] args) { InputStream in = null; OutputStream out = null; try { // Check the arguments if ((args.length != 1)&& (args.length != 2)) throw new IllegalArgumentException("Wrong number of args");
// Set up the streams URL url = new URL(args[0]); // Create the URL in = url.openStream(); // Open a stream to it if (args.length == 2) // Get an appropriate output stream out = new FileOutputStream(args[1]); else out = System.out;
// Now copy bytes from the URL to the output stream byte[] buffer = new byte[4096]; int bytes_read; while((bytes_read = in.read(buffer)) != -1) out.write(buffer, 0, bytes_read); } // On exceptions, print error message and usage message. catch (Exception e) { System.err.println(e); System.err.println("Usage: java GetURL []"); } finally { // Always close the streams, no matter what. try { in.close(); out.close(); } catch (Exception e) {} } } }
作者:言轻 在 海归商务 发贴, 来自【海归网】 http://www.haiguinet.com
|
|
|
返回顶端 |
|
|
|
- 保存论坛所有贴子的算法,并附上JAVA程序 -- 言轻 - (6698 Byte) 2004-2-04 周三, 00:48 (1349 reads)
|
|
|
您不能在本论坛发表新主题, 不能回复主题, 不能编辑自己的文章, 不能删除自己的文章, 不能发表投票, 您 不可以 发表活动帖子在本论坛, 不能添加附件不能下载文件, |
|
|