0

I have a service where I "hit" my site every X Minutes and I want compare the "old" jsoup document to the new one to see if there is a change.

Any thoughts / help ?

public class MyService extends Service {

public int onStartCommand(Intent intent, int flags, int startId) {
    // Let it continue running until it is stopped.

    while(true)
    {

            new DoBackgroundTask().execute();

        return START_STICKY;
    }

}

private class DoBackgroundTask extends AsyncTask<String, String, String> {

    @Override
    protected String doInBackground(String... params) {
       String response;
        response = "It Run!";
        try {
                Document results = Jsoup.connect("my site").get();

        } catch (IOException e) {
        e.printStackTrace();
    }

        return response;
    }

    @Override
    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        new Handler().postDelayed(new Runnable() {
            public void run() {
                new DoBackgroundTask().execute();

            }
        }, 100000);
    }
}
Horizon_Net
  • 5,959
  • 4
  • 31
  • 34
  • Can you be more specific about what your problem is? Are you not able to connect to the site? Not able to compare the results? Looking for a better way of doing so? Something else entirely? – Gabe Sechan Jun 30 '15 at 23:14
  • Hey, sorry about the misunderstanding. I am trying to find a way to compare the 2 documents (the old one and the new one) – Antonis Frs Jun 30 '15 at 23:15

1 Answers1

0

When you hit your site, let Jsoup parse your HTML code:

Document doc = Jsoup.connect("my-site").get();

Then store the results as a String with the current date.

saveNewVersion(new Date(), doc.outerHtml());

Now, find the latest version and compare it with the current version (see https://stackoverflow.com/a/132550/363573):

String oldDoc = loadLastestVersion();

// Find differences with google-diff-match-patch or java-diff-utils...

References:

Community
  • 1
  • 1
Stephan
  • 41,764
  • 65
  • 238
  • 329