我有一个服务,我打"我的网站每X分钟,我想比较" old" jsoup文档到新的文档,看看是否有变化。
有任何想法/帮助吗?
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);
}
}
答案 0 :(得分:0)
当您访问您的网站时,让Jsoup解析您的HTML代码:
Document doc = Jsoup.connect("my-site").get();
然后将结果存储为具有当前日期的String
。
saveNewVersion(new Date(), doc.outerHtml());
现在,找到最新版本并将其与当前版本进行比较(请参阅https://stackoverflow.com/a/132550/363573):
String oldDoc = loadLastestVersion();
// Find differences with google-diff-match-patch or java-diff-utils...
参考文献: