Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

232
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda