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

243
Vistas
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 Respuestas
Responde la pregunta

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 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