brainly.js 778 B

1234567891011121314151617181920212223242526
  1. const brainly = require('brainly-scraper')
  2. module.exports = BrainlySearch = (pertanyaan, jumlah, cb) => {
  3. brainly(pertanyaan.toString(),Number(jumlah)).then((res) => {
  4. let brainlyResult = []
  5. res.data.forEach((ask) => {
  6. let opt = {
  7. pertanyaan: ask.pertanyaan,
  8. fotoPertanyaan: ask.questionMedia
  9. }
  10. ask.jawaban.forEach(answer => {
  11. opt.jawaban = {
  12. judulJawaban: answer.text,
  13. fotoJawaban: answer.media
  14. }
  15. })
  16. brainlyResult.push(opt)
  17. })
  18. return brainlyResult
  19. }).then(x => {
  20. cb(x)
  21. }).catch(err => {
  22. console.log(err.error)
  23. })
  24. }