nans 2014-09-17 14:26
浏览 2244

网页源码下载下来后,汉字成乱码?

我用软件自动下载网页源码,作为监控网站用的,发现字数超过三万字,整个文本的汉字都成乱码,没办法分析,拿去转换编码也没办法矫正。以下是代码
con = (HttpURLConnection) url.openConnection();

con.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");// IE代理进行下载

con.setConnectTimeout(120000);

con.setReadTimeout(120000);

// 获得网页返回信息码

responseCode = con.getResponseCode();

if (responseCode == -1) {

System.out.println(url.toString() + " : connection is failure...");

con.disconnect();

return null;

}

if (responseCode >= 400) //请求失败

{

System.out.println("请求失败:get response code: " + responseCode);

con.disconnect();

return null;

}

        InputStream inStr = con.getInputStream();  
        InputStreamReader istreamReader = new InputStreamReader(inStr, encode);  
        BufferedReader buffStr = new BufferedReader(istreamReader);  

        String str = null;  
        while ((str = buffStr.readLine()) != null)  
            contentBuffer.append(str);  
        inStr.close();  
    } catch (IOException e) {  
        e.printStackTrace();  
        contentBuffer = null;  
        System.out.println("error: " + url.toString());  
    } finally {  
        con.disconnect();  
    }  
  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)
    • ¥15 keil里为什么main.c定义的函数在it.c调用不了
    • ¥50 切换TabTip键盘的输入法
    • ¥15 可否在不同线程中调用封装数据库操作的类
    • ¥15 微带串馈天线阵列每个阵元宽度计算
    • ¥15 keil的map文件中Image component sizes各项意思
    • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏