Jsoup似乎正在缓存,我可以禁用它吗? [英] Jsoup seems to be caching, can I disable this?

查看:347
本文介绍了Jsoup似乎正在缓存,我可以禁用它吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用reddit.com/r/subreddit/random从/r/nocontext获取随机链接.但是,如果我将此代码放入循环中,似乎会使我反复进入同一链接.这使我认为Jsoup正在缓存网页,但是我需要禁用它.这是我的代码:

I'm trying to use reddit.com/r/subreddit/random to get a random link from /r/nocontext. However, it seems to bring me to the same link repeatedly should I put this code in a loop. This brings me to think that Jsoup is caching the webpage, but I need to disable this. Here's my code:

Document doc = null;
try {
    doc = Jsoup.connect("http://www.reddit.com/r/nocontext/random").get();
    Elements elements = doc.select("div.entry.unvoted p.title a.title");

    for (Element link : elements) 
        System.out.println(link.text());

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

任何人都对如何解决此问题有任何见识?

Anyone have any insight on how to fix this problem?

推荐答案

它很可能由服务器缓存. 在其API中查看规则.

It is most probably cached by the server. check the Rules in their API.

尤其是我引用:

大多数页面都会缓存30秒,因此如果出现以下情况,您将不会获得新的数据 您经常请求相同的页面.不要再打相同的页面 而不是每30秒一次.

Most pages are cached for 30 seconds, so you won't get fresh data if you request the same page that often. Don't hit the same page more than once per 30 seconds.

让您的请求每30秒钟一次,看看您的问题是否解决.

so make your request be every 30+ seconds and see if your problem is solved.

这篇关于Jsoup似乎正在缓存,我可以禁用它吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆