从html-element中抓取一个innertext?

时间:2013-09-07 17:43:23

标签: android title

这是我目前的代码:

reader = new BufferedReader(new InputStreamReader(is));
String result = "";

while ((result = reader.readLine()) != null) {
    System.out.println(result);
    if (result.contains("<title>")) {
        webtitle.setText(result.intern());
    }
}

现在,我目前在TextView中得到的是:

<title>This is the website's title</title>

我想要的是:

This is the website's title

我需要更改什么来获取HtmlElement的内部文本?

1 个答案:

答案 0 :(得分:0)

reader = new BufferedReader(new InputStreamReader(is));
String result = "";

while ((result = reader.readLine()) != null) {
    System.out.println(result);
    if (result.contains("<title>")) {
        String tmp = result.intern();
        int start = tmp.indexOf('>');
        webtitle.setText(tmp.substring(start+1,tmp.substring(start).indexOf('<'));
    }
}