Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function scrapePage (url, selectors) {
- return fetch(url)
- .then(response => response.buffer())
- .then(buffer => {
- const {encoding} = detectEncoding(buffer)
- const decoded = iconvLite.decode(buffer, encoding)
- return decoded
- })
- .then(function (html) {
- const $ = cheerio.load(html)
- return {
- title: cleanText($(selectors.title).first().text()),
- author: cleanText($(selectors.author).first().text()),
- description: cleanText($(selectors.description).first().text()),
- cover: $(selectors.cover).attr('src'),
- pageCount: cleanText($(selectors.pageCount).first().text()),
- publishDate: cleanText($(selectors.publishDate).first().text()),
- genre: ''
- }
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement