最近读取一个韩文网站,发现采下的内容全是乱码,不知道怎么解决退请各位支招下。此处就拿三星网站例说:打开http://www.samsung.com/sec/#mobile-devices-home 可以查看到网站编码是utf-8
这里java采集数据以utf-8去读取时发现采下的内容韩文全是乱码httpclient抓取的部分代码:
uefEntity = new UrlEncodedFormEntity(new ArrayList<NameValuePair>(),encoding);
post = new HttpPost(url);
post.setEntity(uefEntity);
post.setHeaders(headers);
response = httpClient.execute(post);
entity = response.getEntity(); // 获取响应实体
if (null != entity) {
result = EntityUtils.toString(entity, encoding);
}
此处encoding传的为utf-8采集中文网站一切正常,请问下韩文要以什么编码进行采集还是要特殊处理?

解决方案 »

  1.   

    在浏览器工具里,查看一下编码,是不是真的是UTF8的。或者用firebug等HTTP协议监测工具查看一下,实际的响应消息中编码类型是不是真的是UTF8。我个人理解,<meta>标签中指定的编码不一定准确,虽然指定的是UTF8的编码,但是如果响应消息中指定的编码为其他类型,就会覆盖<meta>标签里指定的编码
      

  2.   

    EntityUtils.getContentCharSet(entity);也是utf-8的,这应该是反回的实际编码吧,一般采集都先看头里编码,如果为空才去页面抓取相应设置编码格式