【问题标题】:How do I get text content from a website with java? [closed]如何使用 java 从网站获取文本内容? [关闭]
【发布时间】:2018-11-29 19:22:12
【问题描述】:

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

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);
}

【问题讨论】:

标签: java


【解决方案1】:

您可以使用 JSoup 之类的库从 HTML 中获取正文。

https://jsoup.org/cookbook/input/parse-body-fragment

String html = "<div><p>Lorem ipsum.</p>";
Document doc = Jsoup.parseBodyFragment(html);
Element body = doc.body();
String text = body.text();

【讨论】:

    猜你喜欢
    • 2014-07-31
    • 2013-10-30
    • 1970-01-01
    • 1970-01-01
    • 2011-03-03
    • 2012-03-02
    • 1970-01-01
    相关资源
    最近更新 更多