From 3cdc30408e08fc2f5c4d312bf6b9d8e75badfff0 Mon Sep 17 00:00:00 2001 From: Boxuan Li Date: Fri, 26 Oct 2018 21:55:27 +0800 Subject: [PATCH] pre2017.js: Fix wikipedia scraping Fixes https://github.com/coala/gci-leaders/issues/162 --- lib/pre2017.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/pre2017.js b/lib/pre2017.js index d5cbd03..a3878ec 100644 --- a/lib/pre2017.js +++ b/lib/pre2017.js @@ -86,10 +86,12 @@ async function fetchStatistics(year, html) { const statTable = $('table.wikitable.sortable > tbody > tr').slice(1) const tableByYear = statTable - .filter( - (index, element) => - removeInsideBrackets(getListText($, element, 'td')[0]) === String(year) - ) + .filter((index, element) => { + const yearStr = removeNewLine( + removeInsideBrackets(getListText($, element, 'td')[0]) + ) + return yearStr === String(year) + }) .first() const tableData = getListText($, tableByYear, 'td') @@ -114,6 +116,10 @@ function removeInsideBrackets(str) { return str.replace(/(\[.*?\]|\(.*?\)) */g, '') } +function removeNewLine(str) { + return str.replace(/\n/g, '') +} + module.exports = async () => { const wikiResponse = await fetchText(CODEIN_WIKI_URL)