0
would like to search and extract a string that is between tags. Using Javascript only with Node.
Example: Extract information inside any tag and save in some variable.
I don’t know how to implement a code for this. I don’t know if I could be clear.
Example 2 is what I’m trying to do. Search and save the names of the teachers that are on this page. I realized that all are 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)
});
Hi Daniel, search on function
substring
and on regular Expressions that can help you. Also, post in question your code, what you have already done– Ricardo Pontual
Give a practical example of this to facilitate understanding. The way you described the question is vague
– Sorack
I’ll make it better.
– Daniel Vieira
Yes, try to improve and give examples. If it is
HTML
you can use a parser. If it isXML
is already another kind of library.– Sorack
I played an amendment there, I hope it became clearer...
– Daniel Vieira
In that case the
const funcionarios
is an array of H2? if it is, you can iterate over it to pick up each element.– Gabriel Hardoim
No, in this case, this constant receives all the html code of the page.
– Daniel Vieira
I edited my answer down there. See if it helps you out.
– Gabriel Hardoim