Skip to content

Commit

Permalink
pre2017.js: Fix wikipedia scraping
Browse files Browse the repository at this point in the history
Fixes #162
  • Loading branch information
li-boxuan committed Oct 27, 2018
1 parent ae47a18 commit 3cdc304
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/pre2017.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)

Expand Down

0 comments on commit 3cdc304

Please sign in to comment.