Skip to content

Instantly share code, notes, and snippets.

@volkanozcan2
Last active March 26, 2017 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save volkanozcan2/748daa2082111a39d59b5e2f855bd30e to your computer and use it in GitHub Desktop.
Save volkanozcan2/748daa2082111a39d59b5e2f855bd30e to your computer and use it in GitHub Desktop.
node:requests
var request = require("request");
var moment = require("moment");
var fs = require("fs");
var sonuclar = [];
fs.unlink('deneme.txt', (err) => {
if (err) throw err;
console.log('successfully deleted denem.txt');
});
var day = moment("1996-11-16");
for (var _loop = 0; _loop < 10; _loop++) {
var c_date = day.add(7, "days").format("YYYY,MM,DD").replace(/,/g, '');
sonuclar.push(c_date);
}
sonuclar.map(function(x) {
var options = {
method: 'GET',
headers: {
'cache-control': 'no-cache',
cookie: '_ga=GA1.3.498101478.1490376183; _gat=1',
'accept-language': 'en-US,en;q=0.8,tr;q=0.6',
'accept-encoding': 'gzip, deflate, sdch',
referer: 'http://www.millipiyango.gov.tr/sonuclar/_cs_sayisal.php',
dnt: '1',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36',
'x-requested-with': 'XMLHttpRequest',
accept: 'application/json, text/javascript, */*; q=0.01'
}
};
options.url = 'http://www.millipiyango.gov.tr/sonuclar/cekilisler/sayisal/' + x + '.json'
request(options, function(error, response, body) {
if (error) throw new Error(error + "bundan");
// console.log(response.elapsedTime);
var _json = JSON.parse(body);
sonuclar.push({
hafta: _json.data.hafta,
sayılar: _json.data.rakamlarNumaraSirasi.split(" - "),
// time: response.elapsedTime
});
console.log(_json.data.hafta + " ıncı hafta " + _json.data.rakamlarNumaraSirasi.split(" - "));
// console.log(_loop + "****");
fs.appendFile("deneme.txt", +
_json.data.hafta + ":" + _json.data.rakamlarNumaraSirasi.split(" - ") + "\n",
function(err) {
if (err) {
return console.log(err + "y da bundan");
}
});
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment