; readWord success
  
how to download dynamic pages of a BBS using wget cella 2013 Branchable 0 11697
  

The following is a sample case for downloading a freechal.com community.

At first, authorizing cookies have to be prepared:

wget --keep-session-cookies --save-cookies cookies.txt --post-data "LOGINURL=http%3A%2F%2Fwww%2Efreechal%2Ecom&OpenMsg=false&Secret=false&ViewHompy=false&OrgRefer=M&NoTBar=&loginLevel=2&otp1=&otp2=&UserID=vievie&Password=ne5cella&SaveID=false" https://ses.freechal.com/signin/verify.asp

And then, use the following java program as follow:

java SyWget

The SyWget.java is as follow:

-------- start --------

import java.io.*;

class SyWget {
public static void main (String Argv[]) {
int grpId = 987480;
int objSeq = 4;
int pageNo = 1;


try {
for( pageNo=1; pageNo <= 1; pageNo++) {
getPage( grpId, objSeq, pageNo);
}

} catch( NullPointerException e) {
System.err.println( e.toString());
System.exit(1);
} catch( FileNotFoundException e) {
System.err.println( e.toString());
System.exit(1);
} catch( IOException e) {
System.err.println( e.toString());
System.exit(1);
}
}

public static void getPage( int grpId, int objSeq, int pageNo) throws NullPointerException, FileNotFoundException, IOException {
String pageFileName = pageNo + ".html";
String[] wgetList = {"wget", "-O", pageFileName, "--load-cookies", "cookies.txt", "http://bbs.freechal.com/ComService/Activity/BBS/CsBBSList.asp?GrpId=" + grpId
+ "&ObjSeq=" + objSeq + "&PageNo=" + pageNo};

StringBuffer strBuf = new StringBuffer( 50000);

execWget( wgetList);

// FileReader pageFileReader = new FileReader( pageFileName);
FileInputStream pageFileInputStream = new FileInputStream( pageFileName);
InputStreamReader pageFileReader = new InputStreamReader( pageFileInputStream, "euc-kr");


System.out.println("FileReader encodeing=" + pageFileReader.getEncoding());

BufferedReader pageFileBufReader = new BufferedReader( pageFileReader);

for( String line = pageFileBufReader.readLine(); line != null; line = pageFileBufReader.readLine()) {
int beginIndex;
if( ( beginIndex = line.indexOf("CsBBSContent.asp", 0)) != -1) {
int bBeginIndex = line.indexOf("DocId=", beginIndex) + 6; // 6 == "DocId=".length
int endIndex = line.indexOf("\"", bBeginIndex);
String href = line.substring( beginIndex, endIndex);
String docId = line.substring( bBeginIndex, endIndex);
String contentFileName = pageNo + "_" + docId + ".html";
line = line.replace( href, contentFileName);

String[] wgetContent = {"wget", "-O", contentFileName, "--load-cookies", "cookies.txt", "http://bbs.freechal.com/ComService/Activity/BBS/CsBBSContent.asp?GrpId=" + grpId
+ "&ObjSeq=" + objSeq + "&PageNo=" + pageNo + "&DocId=" + docId};
execWget( wgetContent);
}
else if( ( beginIndex = line.indexOf("CsBBSList.asp?", 0)) != -1) {
int bBeginIndex = line.indexOf("PageNo=", beginIndex) + 7; // 7 == "PageNo=".length
int endIndex = line.indexOf("\"", bBeginIndex);
String href = line.substring( beginIndex, endIndex);
String linkedPageNo = line.substring( bBeginIndex, endIndex);
String linkedPageFileName = linkedPageNo + ".html";
line = line.replace( href, linkedPageFileName);
}

strBuf.append( line + "\n");
}
pageFileBufReader.close();
pageFileReader.close();
pageFileInputStream.close();

String str = strBuf.toString();

// FileWriter pageFileWriter = new FileWriter( pageFileName);
FileOutputStream pageFileOutputStream = new FileOutputStream( pageFileName);
OutputStreamWriter pageFileWriter = new OutputStreamWriter( pageFileOutputStream, "euc-kr");
System.out.println("FileWriter encodeing=" + pageFileWriter.getEncoding());
pageFileWriter.write( str, 0, str.length());
pageFileWriter.close();


}



public static void execWget( String[] wgetCommand) throws IOException, NullPointerException {
int outByteNum = 0;
byte[] outBuf = new byte[100000];
int errorByteNum = 0;
byte[] errBuf = new byte[10000];

Process proc = Runtime.getRuntime().exec( wgetCommand);

try {
outByteNum = proc.getInputStream().read( outBuf);
if( outByteNum == outBuf.length) {
System.out.println("output byte buffer outBuf is short!");
System.exit(1);
}

errorByteNum = proc.getErrorStream().read( errBuf);
if( errorByteNum == errBuf.length) {
System.out.println("error byte buffer errBuf is short!");
System.exit(1);
}
} catch( IOException e) {
System.err.println( e.toString());
System.exit(1);
} catch( NullPointerException e) {
System.err.println( e.toString());
System.exit(1);
}

// System.err.println( "" + "(" + outByteNum + ")" + (new String( outBuf)));
// System.err.println( "" + "(" + errorByteNum + ")" + (new String( errBuf)));


proc.destroy();

return;
}

}

-------- end --------