Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用java从网站获取文本内容?_Java - Fatal编程技术网

如何使用java从网站获取文本内容?

如何使用java从网站获取文本内容?,java,Java,根据我的参考,这可能有效: URL url = new URL("www.gmail.com"); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String str; while ((str = in.readLine()) != null) { tr = in.readLine().toString(); System.out.println(st

根据我的参考,这可能有效:

URL url = new URL("www.gmail.com");       
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
    tr = in.readLine().toString();
    System.out.println(str);
}

您可以使用像JSoup这样的库从HTML中获取正文文本


请不要使用所有的篇幅,请努力提出一个完整的问题,一个有足够细节的问题,使其易于回答。请查看和。请参阅:
String html = "<div><p>Lorem ipsum.</p>";
Document doc = Jsoup.parseBodyFragment(html);
Element body = doc.body();
String text = body.text();