2017-02-22 5 views
0

私のアプリはインターネットに接続し、画像とテキストのようなものを得るためにHTMLを得るためにページをスクラブします。しかし、私はいくつかの句読点が実際にはこれを止めるために、そのUnicode 10進コードに変換されることに気づいていますか?句読点をUnicodeに変換するInputStream

public class DownloadPage extends AsyncTask<String, Void, String> { 

    public interface PageResponse { 
     void processFinish(String output); 
    } 

    private PageResponse delegate = null; 

    public DownloadPage(PageResponse delegate){ 
     this.delegate = delegate; 
    } 

    @Override 
    protected String doInBackground(String... urls) { 
     URLConnection connection; 
     try { 
      URL url = new URL(urls[0]); 

      connection = url.openConnection(); 

      String html; 
      InputStream inputStream = connection.getInputStream(); 
      BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); 
      StringBuilder str = new StringBuilder(); 
      String line; 
      while ((line = reader.readLine()) != null) { 
       str.append(line); 
      } 
      inputStream.close(); 
      html = str.toString(); 

      return html; 

     } catch (MalformedURLException e) { 
      e.printStackTrace(); 
      return "Failed"; 
     } catch (IOException e) { 
      e.printStackTrace(); 
      return "Failed"; 
     } 
    } 

    @Override 
    protected void onPostExecute(String s) { 
     super.onPostExecute(s); 
     delegate.processFinish(s); 
    } 
} 

これは、https://www.looemusic.co.uk/news/からの情報を取得しているページです。

This is what comes up with this code.

答えて

0

あなたは問題が自分自身をレンダリングするHTMLあなたのInputStreamであり、そしてない確信している場合は、あなたがにInputStreamReaderの文字セットを設定できます。

new InputStreamReader(inputStream, Charset.UTF-8); 

をこの文字セットがjava.nioのからです.charset。

これが失敗した場合は、クライアントのエンコーディングに問題がないかどうかチェックすることができます。あなたの代わりにUTF-8の別の文字セットを使用したい場合は、単に変更

<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> 

:HTML 4のために

<meta charset="UTF-8"> 

:HTML 5について

:HTMLファイルでこのタグを入れてコード内の名前!

+0

Charset.UTF-8が好きではありません。オプションではありません –