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

247
Visualizações
How can I get specific data from html in React Native?
  const fetchData = async () =>  {

  fetch('https://*******/*****search-value={value}')
  .then(response => response.text())
  .then(data => {
      console.log(data);
  })
  .catch(err => console.error(err));
  }

I succesfully got the data from the api (it returns full html), and I got this response:

<div class="col-md-12">
    <p class="text-info strong">
     Succes.
    </p>
    <table class="table">
        <tr>
            <td width="40%">Number:</td>
            <td>900000000053901</td>
        </tr>
        <tr>
            <td>ID</td>
            <td></td>
        </tr>
        <tr>
            <td>Name:</td>
            <td>Grafit</td>
        </tr>
        <tr>
            <td>Spiece:</td>
            <td>kutya</td>
        </tr>
        <tr>
            <td>Type:</td>
            <td>Border collie</td>
        </tr>
        <tr>
            <td>Gender:</td>
            <td>hím</td>
        </tr>
        <tr>
            <td>Last modified:</td>
            <td></td>
        </tr>
        <tr>
            <td>Dangerous:</td>
            <td>
                                Nem
                            </td>
        </tr>
        <tr>
            <td>Last vaccine:</td>
            <td>Intervet Nobivac DHPPi+RL, 2018.02.17</td>
        </tr>
        <tr>
            <td>isDead:</td>
            <td>
                                Nem
                            </td>
        </tr>

    </table>

Now I want to see the data from class="text-info strong" if Succes or not. If Succes I want to read the html table () and parse it to a json.

{ Number: 900000000053901, ID:"", Name:"Grafit", ... }

How can I achieve this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You could do it with something like this:

function tableToJson(table) {
    const data = [];
    for (let i = 1; i < table.rows.length; i++) {
        const tableRow = table.rows[i];
        const rowData = {};
        rowData[tableRow.cells[0].textContent] =
            tableRow.cells[1].textContent.replace(/\n\ +/gm, '');
        data.push(rowData);
    }
    return data;
}

const dataHTML = document.createElement('div');
dataHTML.innerHTML = data;
const isSuccess =
    dataHTML.querySelector('.text-info.strong').textContent === 'success';
if(!isSuccess) return false;
const table = dataHTML.getElementsByTagName('table')[0];
return tableToJson(table);
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