aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2022-03-05 10:19:25 +0100
committerElias Fleckenstein <eliasfleckenstein@web.de>2022-03-05 10:19:25 +0100
commitd2de7b37f8d8300b36aae1598ed58d3251aa4bd1 (patch)
treef017419dcb168c2dbec761e8780cb266aaf317a6
parentc1e9335a52f7155c8272d8f1563c1ef03e348e5e (diff)
downloadgoogle_images-d2de7b37f8d8300b36aae1598ed58d3251aa4bd1.tar.xz
Fix unresolved promise
-rw-r--r--init.js4
1 files changed, 2 insertions, 2 deletions
diff --git a/init.js b/init.js
index f850b45..fd566ad 100644
--- a/init.js
+++ b/init.js
@@ -3,9 +3,9 @@ const cheerio = require("cheerio")
const jsonic = require("jsonic")
module.exports.search = (query, userAgent = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:97.0) Gecko/20100101 Firefox/97.0") =>
- fetch("https://www.google.com/search?tbm=isch&q=" + encodeURIComponent(query), {headers: {"User-Agent": userAgent}}).then(res =>
+ fetch("https://www.google.com/search?tbm=isch&q=" + encodeURIComponent(query), {headers: {"User-Agent": userAgent}}).then(res => res.text()).then(data =>
jsonic( // jsonic is used because JSON.parse() requires strict JSON and eval() allows for remote code execution
- cheerio.load(res.text(), null, false) // parse HTML
+ cheerio.load(data, null, false) // parse HTML
("script") // find script tags
.toArray() // convert cheerio list to array
.map(script => script.children[0]?.data) // map script tags to their inline code