From 6a0b40b9238c04b68bb8c617f1e98e2976385eb6 Mon Sep 17 00:00:00 2001 From: Zorn Date: Fri, 3 Jul 2020 22:23:23 -0400 Subject: [PATCH 1/2] feat: update selector to handle DOM updates --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index e9b9a85..3df99c3 100644 --- a/index.js +++ b/index.js @@ -11,19 +11,19 @@ function search(query) { const $ = cheerio.load(req.getBody(), { ignoreWhitespace: true }); - let synonyms = $('body #loadingContainer #root div section div p:contains("Synonyms ")').parent().parent().find('ul li span a'); + let synonyms = $('body #loadingContainer #root div section div *:contains("Synonyms ")').parent().find('ul li span a'); synonyms = synonyms.map(function() { return $(this).text(); }).get().sort(); - let antonyms = $('body #loadingContainer #root div section div p:contains("Antonyms ")').parent().parent().find('ul li span a'); + let antonyms = $('body #loadingContainer #root div section div *:contains("Antonyms ")').parent().find('ul li span a'); antonyms = antonyms.map(function() { return $(this).text(); }).get().sort(); return { - synonyms: synonyms, - antonyms: antonyms + synonyms: Array.from(new Set(synonyms)), + antonyms: Array.from(new Set(antonyms)), }; } From 64014933a5a3eb84f4b990082e0715c91bf03cf2 Mon Sep 17 00:00:00 2001 From: dmahfouda Date: Wed, 2 Dec 2020 19:43:13 -0500 Subject: [PATCH 2/2] Updated 'span' tag to 'div' to facilitate parsing --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3df99c3..8d1fb14 100644 --- a/index.js +++ b/index.js @@ -11,12 +11,12 @@ function search(query) { const $ = cheerio.load(req.getBody(), { ignoreWhitespace: true }); - let synonyms = $('body #loadingContainer #root div section div *:contains("Synonyms ")').parent().find('ul li span a'); + let synonyms = $('body #loadingContainer #root div section div *:contains("Synonyms ")').parent().find('ul li div a'); synonyms = synonyms.map(function() { return $(this).text(); }).get().sort(); - let antonyms = $('body #loadingContainer #root div section div *:contains("Antonyms ")').parent().find('ul li span a'); + let antonyms = $('body #loadingContainer #root div section div *:contains("Antonyms ")').parent().find('ul li div a'); antonyms = antonyms.map(function() { return $(this).text(); }).get().sort();