Aklımda Kalası Kelimeler

* давайте работать вместе
* Zarf ve Mazruf, Zerafet(xHoyratlık) ile aynı kökten(za-ra-fe) gelir
* Bedesten
* Suç subuta ermiştir - Suç sabit olmuştur

28 Kasım 2014 Cuma

jQuery requires a window with a document

jQuery ile dom parse etmek içinde gezerek manipüle etmek istediğimde aldığım hataydı: jQuery requires a window with a document

jsdom, cheerio kullanımı tavsiye edilse de jQuery ile çalışmak için bir yol daha var. Şimdilik çok eski diyemeyeceğim 1.8.3 NodeJs tarafında çok fazlaca işlerimi gördüğünden
C:\Projeler\Test>npm install jquery@1.8.3
ile tam sürümünü kurabilirsiniz.

$ ile şöyle çalışabilirsiniz:
var fnCalisAbi = function () {
    var options = {
        method: 'GET',
        host: '127.0.0.1', // Fiddler içinde görünsün deyyu
        port: 8888,        // Fiddlerin dinlediği porta yönlendiriyoruz
        path: 'http://bidibidi.com/tata.aspx',
        headers: {
            Host: 'bidibidi.com',
            'Content-Type': 'application/x-www-form-urlencoded',
            'Cookie': "ASP.NET_SessionId=4etkmibuyjbg1qi3x04eouuz"
        }
    };
    var $ = require('jquery'),
        sayfa='';
    var req = http.request(options, function (res) {
        console.log('STATUS: ' + res.statusCode);
        console.log('HEADERS: ' + JSON.stringify(res.headers));

        res.setEncoding('utf8');  // sayfa cevap olarak utf8 gelecek

        res.on('data', function (chunk) {  // Tek bir pakette gelmezse ki gelmez, her parça geldiğinde
            sayfa+= chunk;                 // sayfa değişkenine ekleyelimki tüm html elimizde olsun
        });

        res.on('end', function (chunk) {   // Aktarım(response, cevap) tamamlandığında jQuery ile işleyelim
            $sayfa = $(sayfa);
            var tbl = $sayfa.find(".cssAdi").parents("table:first").find("tr").map(function() {
                return $(this).attr("style")
                    ? {
                        Cinsi:$(this).find("td:nth(1)").text(),
                        Miktari:$(this).find("td:nth(2)").text(),
                        Birim:$(this).find("td:nth(3)").text(),
                        Aciklama:$(this).find("td:nth(4)").text()
                      }
                    : null;
            }).get();
            console.log("Sonuçta oluşan dizi:");
            console.log(tbl);
        });
    });

    req.on('error', function (e) {
        console.log('problem with request: ' + e.message);
    });

    req.on('end', function (e) {

    });

    req.end();
};