-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs.js
35 lines (28 loc) · 787 Bytes
/
js.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var util = require("util")
var fs = require("fs")
var jsdom = require("jsdom").JSDOM
function mostrar(x,tiene_colores){
if(tiene_colores==undefined){
tiene_colores = true
}
if(tiene_colores){
console.log(util.inspect(x,{colors:true}))
}else{
console.log(x)
}
}
var texto_html = fs.readFileSync(process.argv.slice(-1)[0]).toString()
var dom = new jsdom(texto_html)
var resultados = Array.from(dom.window.document.querySelectorAll(".result")).map(function(x){
var a = x.querySelector("a")
var img = x.querySelector(".result__icon__img")
var div = x.querySelector(".result__snippet")
return [
a.textContent,
a.href,
img?"http:"+img.attributes.src.value:"nulo",
div.textContent
]
})
var enlaces = resultados.map(function(x){return x[1]})
mostrar(enlaces,true)