http://www.qidian.com/Book/BookUpdateList.aspx
上面的页面是起点文学的排行榜页,现在想采集该页面,我用尽了各种办法,采集下来的始终是乱码,各种乱码
代码如下:
public static void download(final String url, final String path,
final String fileName) {
// 建立并打开链接
URLConnection connection = null;
try {
URL downURL = new URL(url);
connection = downURL.openConnection();
connection.connect();
} catch (MalformedURLException e) {
System.out.println("下载链接错误:" + url);
return;
} catch (IOException e) {
System.out.println("打开连接失败:" + url);
return;
} catch (Exception e) {
e.printStackTrace();
return;
} String retCode = connection.getHeaderField(null);
if (retCode == null || retCode.indexOf("200") == -1) {
if(retCode == null)
System.out.println("返回HTTP头错误!");
else
System.out.println("HTTP头返回代码:" + retCode);
return;
} // 读取数据
InputStream is = null;
try {
is = connection.getInputStream();
} catch (IOException e) {
System.out.println("读取数据失败:" + url);
} FileOutputStream fos = null;
try {
File dir = new File(path);
if (!dir.exists())
dir.mkdir();
fos = new FileOutputStream(new File(path, fileName), false);
} catch (FileNotFoundException e) {
System.out.println("文件不存在:" + path + fileName);
} catch (Exception e) {
System.out.println("打开文件失败:" + path + fileName);
} byte buffer[] = new byte[BUFFERSIZE];
DataOutputStream dos = new DataOutputStream(fos);
try {
int num;
// System.out.println("开始下载排行榜");
while ((num = is.read(buffer)) != -1){
String str = new String(buffer);
// String newstr = new String(str.getBytes("iso-8859-1"),"utf-8");
// System.out.println(newstr); dos.write(buffer, 0, num);
}
} catch (IOException e) {
System.out.println("写文件失败:" + path + fileName);
} try {
is.close();
dos.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
如哪位猛将兄能帮忙解决,不胜感激

解决方案 »

  1.   

    晕,起点的是gb2312的编码啊 str.getBytes("iso-8859-1"),"utf-8"); 这句把iso8859-1改成gbk,应该就可以了
      

  2.   

    str.getBytes("iso-8859-1"),"utf-8"); 
    那句已经注起来了,我那是调试的时候留下的,试尽了各种编码都不行,有位同仁说可能是起点那边把网页加密了,貌似很神秘的样子
      

  3.   

    什么叫指定一个defaut,不太懂啊
    我只知道用上面的程序,下载别的网页都可以,包括.aspx后缀的网页,只有那个页面http://www.qidian.com/Book/BookUpdateList.aspx 是乱码。
      

  4.   

    http://dev2dev.bea.com.cn/bbs/thread.jspa?forumID=121&threadID=25371&messageID=150149