Created
May 26, 2017 14:36
-
-
Save pedrotnascimento/09dc255fb9c255183bc8e9c9bc03af62 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var http = require('https'); | |
var cheerio = require('cheerio'); | |
http.get('https://play.google.com/store/apps/details?id=com.totvs.globo2777&hl=en', (res) => { | |
const { statusCode } = res; | |
const contentType = res.headers['content-type']; | |
let error; | |
// if (statusCode !== 200) { | |
// error = new Error(`Request Failed.\n` + | |
// `Status Code: ${statusCode}`); | |
// } else if (!/^application\/json/.test(contentType)) { | |
// error = new Error(`Invalid content-type.\n` + | |
// `Expected application/json but received ${contentType}`); | |
// } | |
if (error) { | |
console.error(error.message); | |
// consume response data to free up memory | |
res.resume(); | |
return; | |
} | |
res.setEncoding('utf8'); | |
let rawData = ''; | |
res.on('data', (chunk) => { | |
rawData += chunk; | |
}); | |
res.on('end', () => { | |
try { | |
const parsedData = rawData; | |
// console.log(parsedData); | |
// $ = cheerio.load(rawData); | |
// var a = $('div[itemprop="softwareVersion"]').get(0); | |
// console.log("VERSÃO" + a.children[0].data.trim()); | |
firstMatchInx = rawData.search('itemprop="softwareVersion"'); | |
var temp = rawData.slice(firstMatchInx, rawData.length); | |
firstInxTagValue = temp.search(">"); | |
secondInxTagValue = temp.search("<"); | |
temp = temp.slice(firstInxTagValue+1, secondInxTagValue); | |
console.log(temp.trim()); | |
} catch (e) { | |
console.error(e.message); | |
} | |
}); | |
}).on('error', (e) => { | |
console.error(`Got error: ${e.message}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment