Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

221
Views
Converting mailparser HTML into DOM elements?

With mailparser when I get a lot of HTML codes how can I convert them into DOM Elements? I want to access specific HTML elements.

This is my code:

var imaps = require('imap-simple');
const _ = require('lodash');
const simpleParser = require('mailparser').simpleParser;
const cheerio = require('cheerio');

var config = {
    imap: {
        user: 'xxx',
        password: 'xxx',
        host: 'xxx',
        port: 993,
        tls: true,
        authTimeout: 4000
    }
};

imaps.connect(config).then(function (connection) {
    return connection.openBox('INBOX').then(function () {
        var searchCriteria = [
            'UNSEEN'
        ];
        var fetchOptions = {
            bodies: ['HEADER', 'TEXT', ''],
        };
        return connection.search(searchCriteria, fetchOptions).then(function (messages) {
            messages.forEach(function (item) {
                var all = _.find(item.parts, { "which": "" })
                var id = item.attributes.uid;
                var idHeader = "Imap-Id: "+id+"\r\n";
                simpleParser(idHeader+all.body, (err, mail) => {
                    if (mail.subject.indexOf('example.com') > -1) {

                        var dom = mail.html;

                        const $ = cheerio.load(mail.html);
                        var testing = $('span')[0].text();

                      } else {
                        //return false;
                    }
                });
            });
        });
    });
});

I tried with cheerio but had no luck. How can I get access to each HTML element?

Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

$('span')[0] isn't a cheerio object. You can try $('span').first().text() instead.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!