dijs / wiki

Wikipedia Interface for Node.js
MIT License
315 stars 61 forks source link

When i use with any loop it gives me erroe #147

Closed GreXLin85 closed 3 years ago

GreXLin85 commented 3 years ago
const wiki = require('wikijs').default;
const { writeFileSync } = require("fs")
const dates = require("./getDates")
for(let i = 0; i < dates.length; i++  ) {
    (function(i){
        wiki()
            .page(dates[i])
            .then(page => page.content()).then((value => {
                    writeFileSync(`./data/${dates[i]}.json`,JSON.parse(value))
                    console.log(`${dates[i]} imported`)
                }
            )
        ).catch((err) => console.error(`${dates[i]} error\n${err}`))
    })(i)
}

When i run this script it gives me errors like this;

FetchError: invalid json response body at http://en.wikipedia.org/w/api.php?format=json&action=query&redirects=&prop=info%7Cpageprops&inprop=url&ppprop=disambiguation&titles=March_28&origin=* reason: Unexp
ected token < in JSON at position 0
March_15 error

What should i do?

pulpdrew commented 3 years ago

See https://github.com/dijs/wiki/issues/136