Last active
September 24, 2015 13:13
-
-
Save flashbag/45c4931171c20fbcd549 to your computer and use it in GitHub Desktop.
ap.if.ua - orenda parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var $; | |
var request = require('request'); | |
var cheerio = require('cheerio'); | |
var pageCount = 6; | |
var pageUrl = "http://ap.if.ua/index.php?page=5&bl=1&pg=PAGE&roz=1&cat=1&rub=14&find=&foto=&sort=1"; | |
var tableCssQuery = 'center > div > table > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(2) > table > tbody > tr:nth-child(3) table:not(:nth-child(1))'; | |
var tableCssQuery = 'center > div > table tr:nth-child(2) > td > table tr > td:nth-child(2) > table tr:nth-child(3) table:not(:nth-child(1))'; | |
var getPage = function(pageNumber, callback) { | |
var url = pageUrl.replace('PAGE', pageNumber); | |
console.log(url); | |
request(url, function(error, response, body) { | |
// console.log(body); | |
if (error) { | |
console.log(error); | |
return; | |
} | |
$ = cheerio.load(body); | |
var tables = []; | |
var results = $(tableCssQuery); | |
for (var key in results) { | |
// if (parseInt()) | |
if (results[key].hasOwnProperty('name') && results[key].name === 'table') { | |
tables.push(results[key]); | |
} | |
} | |
callback(tables); | |
}); | |
}; | |
for (var i = 0; i <= pageCount; i++) { | |
}; | |
getPage(1, function(tables){ | |
console.log(tables[0]); | |
// table1.querySelector('td:nth-child(3)').innerText | |
}); | |
// http://ap.if.ua/index.php?page=5&roz=1&cat=1&rub=14 | |
// http://ap.if.ua/index.php?page=5&roz=1&cat=1&rub=14&bl=1&pg=2&sort=11 | |
// http://ap.if.ua/index.php?page=5&roz=1&cat=1&rub=14&bl=1&pg=3&sort=11 | |
// http://ap.if.ua/index.php?page=5&bl=1&pg=3&roz=1&cat=1&rub=14&find=&foto=&sort=1 | |
// http://ap.if.ua/index.php?page=5&bl=1&pg=3&roz=1&cat=1&rub=14&find=&foto=&sort=1 | |
// http://ap.if.ua/index.php?page=5&bl=1&pg=3&roz=1&cat=1&rub=14&find=&foto=&sort=1 | |
// http://ap.if.ua/index.php?page=5&bl=1&pg=3&roz=1&cat=1&rub=14&find=&foto=&sort=1 | |
// http://ap.if.ua/index.php?page=5&bl=1&pg=3&roz=1&cat=1&rub=14&find=&foto=&sort=1 | |
// http://ap.if.ua/index.php?page=5&bl=1&pg=3&roz=1&cat=1&rub=14&find=&foto=&sort=1 | |
// var tables = document.querySelectorAll('body > center > div > table > tbody > tr:nth-child(2) > td > table > tbody > tr > td:nth-child(2) > table > tbody > tr:nth-child(3) table:not(:nth-child(1))'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "apifua-orenda-parser", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "npm test", | |
"start": "node index.js" | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"cheerio": "^0.19.0", | |
"request": "^2.63.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment