我正在使用YQL从另一个每天更新的站点抓取一些数据,但是不管我怎么努力,返回的数据至少是一天前的数据。换句话说,我抓取的不是网站上的实际数据。我假设它被缓存了,根据我的读取,我需要使用某种缓存破坏技术来强制它获得新的数据。下面是我的调用代码的核心:
SomeClass.prototype.testfunc = function () {
var _this = this;
var site = "http://www.somesite.shtml";
var xpath = '//table[@id="someId"]/tbody/tr';
var yql = "https://query.yahooapis.com/v1/public/yql?q=" + encodeURIComponent("select * from html where url='" + site + "' and xpath='" + xpath + "'") + "&format=json&callback=?&rnd=2";
$.ajax({
url: yql,
dataType: 'json',
cache: false,
success: _this.testFunc
});
SomeClass.prototype.testFunc = function (data) {
if (data != undefined) {
//handle returned data
}
}我尝试了两种不同的缓存破坏技术来让它检索当前数据: 1)在ajax调用中使用"cache: false“;2)在yql字符串的末尾添加"&rnd=#”,我在测试中手动将其更改为不同的数字,看看是否会有所不同。
我得到了数据,但不幸的是它仍然是一天前的数据。似乎这两种方法都不起作用,我想知道我可以做些什么来获得最新的数据。
发布于 2018-05-24 04:18:29
您需要在site变量中添加一个查询字符串以避免缓存,如下所示:
var site = "http://www.somesite.shtml?t=<timestamp>";
https://stackoverflow.com/questions/44311993
复制相似问题