Raymond Seger
Raymond Seger

Reputation: 1130

Is there any tool to get data from website?

Let's say I have this link called: http://user.com/1345, and that link returns a JSON. Now I want a tool that can loop from http://user.com/1 to http://user.com/1345 and save that JSON data to a file. Anyone knows a good tool for that?

Upvotes: 0

Views: 35

Answers (2)

niutech
niutech

Reputation: 29962

In JavaScript:

var allData = [], xhr;
for (var i = 1; i <= 1345; i++) {
    xhr = new XMLHttpRequest();
    xhr.addEventListener("load", function () {
        allData.push(JSON.parse(this.responseText));
    });
    xhr.open("GET", "http://user.com/" + i);
    xhr.send();
}
window.open('data:text/json;charset=utf8,' + encodeURIComponent(allData), '_blank');

Upvotes: 1

NikxDa
NikxDa

Reputation: 4185

You can use C# to do so.

for (var i = 0; i < 1345; i++) 
    System.IO.File.WriteAllText (i.ToString (), new WebClient.DownloadString ("http://user.com/" + (i + 1).ToString()));

Upvotes: 0

Related Questions