Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. function scrapePage (url, selectors) {
  2. return fetch(url)
  3. .then(response => response.buffer())
  4. .then(buffer => {
  5. const {encoding} = detectEncoding(buffer)
  6. const decoded = iconvLite.decode(buffer, encoding)
  7.  
  8. return decoded
  9. })
  10. .then(function (html) {
  11. const $ = cheerio.load(html)
  12.  
  13. return {
  14. title: cleanText($(selectors.title).first().text()),
  15. author: cleanText($(selectors.author).first().text()),
  16. description: cleanText($(selectors.description).first().text()),
  17. cover: $(selectors.cover).attr('src'),
  18. pageCount: cleanText($(selectors.pageCount).first().text()),
  19. publishDate: cleanText($(selectors.publishDate).first().text()),
  20. genre: ''
  21. }
  22. })
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement