-1

So, I've got raw HTML text I've got from an HTTP request, now I want to parse it and get some elements from it to use into my program, how can I apply CSS selectors to the response I've got?

Is there any way to convert this string to an HTML like object in which I can run CSS selectors queries?

What should I do?

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;
}
lucasfcosta
  • 285
  • 2
  • 10
  • you should post your code snippet with your question – Shehary Jul 26 '15 at 20:35
  • Lookup regular expressions. They let you grab pieces from text based on patterns (like the contents of every Nth div). Maybe [this](http://stackoverflow.com/questions/4235445/get-started-with-regular-expression/4235922) could be a good starting point. – Jasper Jul 26 '15 at 20:38
  • Hi Jasper, thanks for your help, I know about RegExp's but I want something easier since I've gotta find multiple elements on the page. – lucasfcosta Jul 26 '15 at 20:44

1 Answers1

0

http://jsoup.org

I just found what I was looking for!

lucasfcosta
  • 285
  • 2
  • 10