如何将css选择器应用于java中的原始HTML文本



我从HTTP请求中获得了原始HTML文本,现在我想解析它并从中获取一些元素用于我的程序,我如何将CSS选择器应用于我得到的响应?

是否有任何方法将此字符串转换为HTML类对象,我可以在其中运行CSS选择器查询?

我该怎么办?

public String getPage(int page) {
    HttpGet get = new HttpGet("http://myurl.com");
    String body = null;
    try {
        CloseableHttpResponse response = httpClient.execute(get);
        HttpEntity responseEntity = response.getEntity();
        body = EntityUtils.toString(responseEntity);
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    System.out.println(body);
    return body;
}

http://jsoup.org

我刚刚找到了我要找的东西!

最新更新