我想從網上獲取文本,我編寫代碼,使用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>
這是得到的所有文本,我只想得到49.156.53.152 – phucloi89
看到我的編輯,我包括分裂功能 – Greezer
什麼是分離[];我不明白你的想法 – phucloi89