是否有类似于Java中的WebClient.DownloadString的内容? [英] Is there something similar to WebClient.DownloadString in Java?
本文介绍了是否有类似于Java中的WebClient.DownloadString的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想下载网站的html源代码以解析一些信息.如何在Java中完成此操作?
I want to download the html source code of a site to parse some info. How do I accomplish this in Java?
推荐答案
只需从从openStream()返回的URL的InputStream中附加一个BufferedReader(或任何读取字符串的内容)即可.
Just attach a BufferedReader (or anything that reads strings) from a URL's InputStream returned from openStream().
public static void main(String[] args)
throws IOException
{
URL url = new URL("http://stackoverflow.com/");
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
String s = null;
while ((s = reader.readLine()) != null)
System.out.println(s);
}
这篇关于是否有类似于Java中的WebClient.DownloadString的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文