Thursday, 3 May 2018

query HTML String using jsoup

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.text.DecimalFormat;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

import org.apache.commons.lang.RandomStringUtils;
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

Public Class Test
{

public void m1(){
try {
URL myUrl = new URL("https://www.hello.com/abc/abo.php");
URLConnection yc = myUrl.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream(), "UTF-8"));
String inputLine;
StringBuilder a = new StringBuilder();
while ((inputLine = in.readLine()) != null)
a.append(inputLine);
in.close();
String str1 = a.toString();
Document parsedHtmlFragment = Jsoup.parse(str1);
Elements matchingLIs = parsedHtmlFragment.select("#ID");

for (Element matchingLI : matchingLIs) {
cGuid = matchingLI.text();
}

} catch (Exception e) {
// TODO: handle exception
} // TODO Auto-generated method stub
}