确定在 Javascript 中调用的 JSON 文件以在 cURL 中用于数据挖掘 - twitter 像“更多”一样;按钮
我正在尝试提取类似于 Twitter 的网站的历史消息流。基本上我们都知道 Twitter 上的“更多”按钮。这个网站有类似的东西,看起来它抓取一个 JSON 对象并解析它。我怎样才能找出 JSON 对象所在的位置,以便我可以使用 CURL 之类的东西来挖掘数据......
更多 JavaScript 代码如下所示:
more : function () {
if (!this.max_id)
return false;
var c = this;
if ($("#updates-more .message").length == 0) {
var b = $("#updates .message:last");
if (b.length > 0) {
b = parseInt(b.attr("id").replace("message_", ""), 10);
if (!isNaN(b))
this.max_id = b
}
}
var a = {
stream : this.stream,
max : this.max_id
};
if (this.poll_id)
a.item_id = this.poll_id;
this.paused ||
$("a.pause").trigger("click");
$("#more-button").hide();
$("#more-button-loading").show();
$.getJSON("/streams/poll?" + $.param(a), function (d) {
$("#more-button-loading").hide();
if (d.messages) {
d.more === false ? $("#more-button").hide() : $("#more-button").show();
var f = [],
g = [];
$(d.messages).find("li.message").each(function () {
g.push($($(this).outerHtml()));
f.push(parseInt($(this).attr("data-ape").replace("messages_", ""), 10))
});
if (g.length > 0) {
if (d.max)
c.max_id = d.max;
g[0].addClass("break");
$("#spaceape").trigger("broadcast", {
messages : f.join(","),
object : {
id : a.stream,
type : "stream"
},
verb : "append",
type : "messages"
});
for (d = 0; d < g.length; d++) {
g[d].find(".body").stText();
g[d].find(".msgDate").stDate();
g[d].appendTo("#updates-more")
}
}
}
})
}
I'm trying to extract a stream of historical messages of a site much like twitter. Basically we all know the 'MORE' button it Twitter. This site has something similar and looks like it grabs a JSON object and parses it. How can I figure out what/where the JSON object is located so I can use something like CURL to mine the data...
The more JavaScript code is shown here:
more : function () {
if (!this.max_id)
return false;
var c = this;
if ($("#updates-more .message").length == 0) {
var b = $("#updates .message:last");
if (b.length > 0) {
b = parseInt(b.attr("id").replace("message_", ""), 10);
if (!isNaN(b))
this.max_id = b
}
}
var a = {
stream : this.stream,
max : this.max_id
};
if (this.poll_id)
a.item_id = this.poll_id;
this.paused ||
$("a.pause").trigger("click");
$("#more-button").hide();
$("#more-button-loading").show();
$.getJSON("/streams/poll?" + $.param(a), function (d) {
$("#more-button-loading").hide();
if (d.messages) {
d.more === false ? $("#more-button").hide() : $("#more-button").show();
var f = [],
g = [];
$(d.messages).find("li.message").each(function () {
g.push($($(this).outerHtml()));
f.push(parseInt($(this).attr("data-ape").replace("messages_", ""), 10))
});
if (g.length > 0) {
if (d.max)
c.max_id = d.max;
g[0].addClass("break");
$("#spaceape").trigger("broadcast", {
messages : f.join(","),
object : {
id : a.stream,
type : "stream"
},
verb : "append",
type : "messages"
});
for (d = 0; d < g.length; d++) {
g[d].find(".body").stText();
g[d].find(".msgDate").stDate();
g[d].appendTo("#updates-more")
}
}
}
})
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您要查找的脚本行是这样的:
$.getJSON("/streams/poll?" + $.param(a), function (d) {
该行执行 JSON向服务器发出请求,并返回一个 JSON 对象“d”,其中包含一个消息列表,每个消息都包含我猜您正在寻找的数据。你在找什么?
The line of script you're looking for up there is this:
$.getJSON("/streams/poll?" + $.param(a), function (d) {
That line does the JSON request to the server, and returns a JSON object 'd'. 'd' Contains a list of messages, each with the data I'm guessing you're looking for. This was a bit of an open ended question - is this what you were looking for?