【发布时间】:2017-07-12 09:49:24
【问题描述】:
我的应用程序连接到互联网并清理页面以获取 html 以获取图像和文本等内容。但是我注意到一些标点符号实际上被转换为它的 unicode 十进制代码,无论如何要阻止这个?
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/。
【问题讨论】:
标签: java android html unicode android-asynctask