我想从网页上阅读文本。我不想获取网页的 HTML 代码。我找到了这段代码:
try {
// Create a URL for the desired page
URL url = new URL("http://www.uefa.com/uefa/aboutuefa/organisation/congress/news/newsid=1772321.html#uefa+moving+with+tide+history");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
str = in.readLine().toString();
System.out.println(str);
// str is one line of text; readLine() strips the newline character(s)
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
但是这段代码给了我网页的 HTML 代码。我想在这个页面中获取整个文本。我怎样才能用 Java 做到这一点?
原文由 Rigor Mortis 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可能想为此查看 jsoup :
这个例子是他们网站上的一个例子的摘录。