Question

I'm coming from a scientific computation background and do have some history with some popular and non-popular (ad hoc) programming languages but I'm completely alien to client side programming and JavaScript.

I've written some trivial JavaScript for my Greasemonkey settings before but that's all.

My question concerns:   http://www.ise.org/sirketler/sirketler.aspx

I'm trying to get all the data about securities and companies from the table given in the URL above which is the site of Turkish İstanbul Stock Exchange.

This data is given within a grid table classified according to the letters which the name of the company begins and at a maximum of 10 rows per grid is given as one can see. Also in the bottom right of the page, there writes how many pages is this info is spread.

For example, you can call from the Firebug console:

__doPostBack('ctl00$cphContent$ctl00$lbtnT','')

for getting the companies starting with 'T' and you can browse the tabs of these table by issuing:

__doPostBack('ctl00$cphContent$ctl00$radGridSirketler$ctl00$ctl03$ctl01$ctl05','')
__doPostBack('ctl00$cphContent$ctl00$radGridSirketler$ctl00$ctl03$ctl01$ctl07','')
__doPostBack('ctl00$cphContent$ctl00$radGridSirketler$ctl00$ctl03$ctl01$ctl09','')

etc. for 1st, 2nd and 3rd pages of this table respectively.

I've tried to serialize this by issuing __doPostBack() method for a given array of letters and numbers by concatenating them to the fixed string above but it did not succeed.

So how can I use __doPostBack() method and append all of these resulting sub tables and get the overall data?

Is there a resource to read for such kind of tasks?

I apologize for my amateur question from all JS hackers.

Was it helpful?

Solution

Hopefully this example will enlighten your path:

// ==UserScript==
// @name           Examples : sirketler
// @namespace      http://gm.wesley.eti.br/examples
// @description    Simulation of an aspx PostBack request
// @include        http://www.ise.org/sirketler/sirketler.aspx
// @require        http://userscripts.org/scripts/source/63808.user.js
// @require        http://userscripts.org/scripts/source/89515.user.js
// ==/UserScript==

AspxPostBackRequest({
    "url" : "http://www.ise.org/sirketler/sirketler.aspx",
    "manager" : "ctl00$ScriptManager1",
    "eventTarget" : "ctl00$cphContent$ctl00$lbtnT",
    "callback" : function(xhr)
    {
        var content = document.createElement("div");
        content.innerHTML = xhr.responseText.split("|")[3];

        alert(xpath("./div/table/tbody/tr", content).map(function(row)
        {
            return [].slice.call(row.cells).map(function(col)
            {
                return col.textContent.replace(/^\s+|\s+$/gm, "");
            });
        }).join("\n"));
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top