How to remove information in a text?

0

I would like to fetch and extract a string that is between tags. Using only JavaScript with Node.

Example: Extract information inside any tag and save to some variable.

I'm not sure how to implement code for this. I do not know if I could be clear.

Example2 is what I'm trying to do. Search and save the names of teachers on this page. I noticed that everyone is among the header2 tags ...

    const url = 'http://www.ppg-educacao.uff.br/novo/index.php/corpo-docente'
const axios = require('axios')

axios.get(url).then(response =>{
    const funcionarios = response.data
    console.log(funcionarios) //Somente para verificar as informações da página foram extraidas.
    //Eu gostaria de salvar o nome de todos os professores, e percebi que todos estão entre a tag <h2>...
    const tag = funcionarios.querySelector("h2")
    const conteudoDeTextoDaTag = tag.textContent
    console.log(conteudoDeTextoDaTag)
});
    
asked by anonymous 08.08.2018 / 18:40

3 answers

0

Consider using a parser HTML like cheerio . For your example it would look like:

const cheerio = require('cheerio');
const $ = cheerio.load(response.data);

console.log($('h2').text());

With it you can use CSS selectors to extract relevant information from the HTML in question.

    
08.08.2018 / 19:31
0

Hey, try doing this:

trechoRetirado= '' + trechoRetirado;

and then, trechoRetirado.substring (13);

Source: link

    
08.08.2018 / 18:57
0

Many thanks to all for the time offered to this doubt and for the knowledge to me last. Grateful and the issue was resolved by Sorack's response.

    
08.08.2018 / 19:58