3

https://stackoverflow.com/10m would be very interesting if you ask me: logging values periodically, and such.
However, a recent issue I had showed that I can't just access it.

Since I've found no methods to gather out these numbers, is there any chance to query these numbers regularly anywhere?

1 Answer 1

2

You can get this data easily by scraping or by using the websocket interface that Stack Exchange helpfully leaves available.

If you are making an application or webpage, just fetch stackoverflow.com/10m via your app-language's standard fetch/scrape utilities. EG: cURL if you are using PHP, etc.

For client side applications, make a Greasemonkey/Tampermonkey/user script and use GM_xmlhttpRequest(). It doesn't have the CORS restrictions.

For super-realtime, JS driven pages, the websocket is open cross-domain (at least until too many people abuse it).

See an example using the websocket at jsBin.

Or run this code from your browser's console:

var ws          = new WebSocket("ws://qa.sockets.stackexchange.com/");
ws.onmessage    = function (messObj) {
    var payload = JSON.parse (messObj.data);
    var statName;

    switch (payload.action) {
        case "1-qcnt-feed":
            statName    = 'Questions';
        break;
        case "1-acnt-feed":
            statName    = 'Answers';
        break;
        case "1-evc-feed":
            statName    = 'Edits, Votes and Comments';
        break;
        default:
            statName    = 'Error! action == "' + payload.action + '".';
        break;
    }

    console.log (statName + ': ' + payload.data);
};
ws.onopen       = function () {
    ws.send ("1-evc-feed");
    ws.send ("1-acnt-feed");
    ws.send ("1-qcnt-feed");
};
window.ws = ws;  //debug:  Allows you to enter ws.close() from console.
4
  • "For super-realtime, JS driven pages, the websocket is open cross-domain (at least until too many people abuse it)." That is strange because I got an error when I attempted to make a standard GET˙request via jQuery. Commented Feb 10, 2016 at 14:17
  • Websockets and GET are quite a bit different. And, jQuery is subject to CORS, the other approaches are not. Did you try the code listed or visit the demo page? Commented Feb 10, 2016 at 16:30
  • Oh, I didn't know yet. I haven't tried the code yet, gonna reply if something happens. Commented Feb 10, 2016 at 16:57
  • It works, I could even adapt it to save values to variables. Thank you very much! Commented Feb 10, 2016 at 21:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .