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

148
Vistas
How to get second part of a url by splitting or parsing while page.evaluate oeprating

Assume that, I have
countries/eg
countries/us
countries/gr
etc.

I want to take only country code part as a string for each item in details as cc. But I want to do that during the page.evaluate operation. In my code I had undefined for each item in this case. How can I do that? Please help me. Thanks in advance.

getDetails: async (lineBaseSelector) => {
        try {

            let url = await page.url();

            function parseUrl( url ) {
                var a = document.createElement('a');
                a.href = url;
                return a;
            }
            
            const details = await page.evaluate((x) => {
                const data = {
                    cc : parseUrl(document.querySelector(`${x}`).getAttribute('href').toLowerCase()).search,
                    name: document.querySelector(`${x}`).innerText.toLowerCase(),
                    url: document.querySelector(`${x}`).getAttribute('href'),
                    last_update: Date.now()
                }
                return Promise.resolve(data);
            }, lineBaseSelector);

            return details;

        } catch (error) {
            console.log(error)
        }
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

 const data = {
                    cc : document.querySelector(`${x}`).getAttribute('href').toLowerCase().toString().split("/")[1],
                    name: document.querySelector(`${x}`).innerText.toLowerCase(),
                    url: document.querySelector(`${x}`).getAttribute('href'),
                    last_update: Date.now()
                }

It is possible with split oepration. In here, index is 1 because of the first part of url has index of 0th.

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