我想从网络上获取文本,我编写了代码,使用 indexOf 和 subString,但它不起作用。
int index = response_str.indexOf("Remote IP Address:");
index += "Remote IP Address:".length();
index += "</div><br /><div id=\"value1\">".length();
int end = response_str.indexOf("</div><br /><br />", index);
String strIP = response_str.substring(index, end);
Log.d("","Hello" + strIP );
这是示例文本,我想得到49.156.53.152
<body>
<div id="title">Remote IP Address:</div><br /><div id="value1">**49.156.53.152**</div><br /><br />
<div id="title">UserAgent:</div><br /><div id="value2">Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11</div><br /><br />
<!-- Everyone of CCorp employees, Good luck ! --><br />
</body>