我正在我的项目中工作,需要使用网页内容的特定部分而不是网站的整个数据。有什么办法可以在android中做到这一点?
问问题
20 次
1 回答
2
在使用所需的部分内容之后,我更喜欢下载整个网络数据。首先下载这样的数据。
public static void main(String[] args) {
URL url;
InputStream is = null;
BufferedReader br;
String line;
try {
url = new URL("your.website/");
is = url.openStream(); // throws an IOException
br = new BufferedReader(new InputStreamReader(is));
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (MalformedURLException mue) {
mue.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
if (is != null) is.close();
} catch (IOException ioe) {
// nothing to see here
}
}
}
之后,您可以使用line收集所需的数据。
于 2021-03-21T19:14:17.850 回答