Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

230
Vistas
How would I get a specific field in this html document using javascript (nodejs)
<Response>
<SMSMessageData>
    <Message>Sent to 1/1 Total Cost: NGN 2.2000</Message>
    <Recipients>
        <Recipient>
            <number>+9109929199111</number>
            <cost>NGN 2.2000</cost>
            <status>Success</status>
            <statusCode>101</statusCode>
            <messageId>ATXid_f615eb5c6e901459e52d67d045a55355</messageId>
            <messageParts>1</messageParts>
        </Recipient>
    </Recipients>
</SMSMessageData>

I want to just extract the element in the number tag using javascript (nodejs) code...............................................................................................

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

you need to use a parser such as cheerio

then you need to read/provide data to it (the HTML), and then you can select the data you need by using its API:

const cheerio = require('cheerio');

const data = `
<Response>
<SMSMessageData>
    <Message>Sent to 1/1 Total Cost: NGN 2.2000</Message>
    <Recipients>
        <Recipient>
            <number>+9109929199111</number>
            <cost>NGN 2.2000</cost>
            <status>Success</status>
            <statusCode>101</statusCode>
            <messageId>ATXid_f615eb5c6e901459e52d67d045a55355</messageId>
            <messageParts>1</messageParts>
        </Recipient>
    </Recipients>
</SMSMessageData>
</Response>
`;


const $ = cheerio.load(data);

const num = $('number').text();

console.log(num);
about 4 years ago · Juan Pablo Isaza Denunciar

0

Using the getElementsByTagName which will return the element with the specified tag (in your case the number tag). then you can select the first element use the innerText property to extract the text value of the element.

const el = document.getElementsByTagName('number')[0];
console.log(el.innerText);
<Response>
<SMSMessageData>
    <Message>Sent to 1/1 Total Cost: NGN 2.2000</Message>
    <Recipients>
        <Recipient>
            <number>+9109929199111</number>
            <cost>NGN 2.2000</cost>
            <status>Success</status>
            <statusCode>101</statusCode>
            <messageId>ATXid_f615eb5c6e901459e52d67d045a55355</messageId>
            <messageParts>1</messageParts>
        </Recipient>
    </Recipients>
</SMSMessageData>

about 4 years ago · Juan Pablo Isaza Denunciar

0

To do this, simply tell the system to fetch the HTML element by calling document.querySelector("number"), and then use the innerText property to get the text content of the string. Use the code below to set a variable content to the text inside of the number tag.

var numberElement=document.querySelector("number"); //Fetch the element
var content=numberElement.innerText; //Retrieve its contents
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda