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

119
Visualizações
Looping through with JS to get info from HTML list on Chrome Console

I am trying to get the data of property transactions from a site using Javascript on the Google Chrome console.

So far, I've figured out how to get the info in a property object for the first property using this code:

var property = [{}]

property[0]['Name']  = document.querySelector("#closed-deals-container > section > div > div.profile-recent-transactions.profile-recent-transactions--paginated > div:nth-child(1) > div > div.uc-listingCard-body > div.uc-listingCard-content > div > div.uc-listingCard-titles > a").innerText;

property[0]['City-State-Zip'] = document.querySelector("#closed-deals-container > section > div > div.profile-recent-transactions.profile-recent-transactions--paginated > div:nth-child(1) > div > div.uc-listingCard-body > div.uc-listingCard-content > div > div.uc-listingCard-titles > h2").innerText;

property[0]['Price'] = document.querySelector("#closed-deals-container > section > div > div.profile-recent-transactions.profile-recent-transactions--paginated > div:nth-child(1) > div > div.uc-listingCard-body > div.uc-listingCard-content > div > div.uc-listingCard--priceGrid-sm > div").innerText;

property[0]['Beds'] = document.querySelector("#closed-deals-container > section > div > div.profile-recent-transactions.profile-recent-transactions--paginated > div:nth-child(1) > div > div.uc-listingCard-body > div.uc-listingCard-content > div > div.uc-listingCard-subStats.checkable-undefined > div.uc-listingCard-subStat.uc-listingCard-subStat--beds").innerText;

property[0]['Baths'] = document.querySelector("#closed-deals-container > section > div > div.profile-recent-transactions.profile-recent-transactions--paginated > div:nth-child(1) > div > div.uc-listingCard-body > div.uc-listingCard-content > div > div.uc-listingCard-subStats.checkable-undefined > div.uc-listingCard-subStat.uc-listingCard-subStat--baths").innerText;

There are 26 other properties on the list, and I'd like to loop through all of them and put them in the property object. I think I need to do a for loop, but I am having trouble figuring out how to execute it.

UPDATE:

The code below solved most of the issue, but I'm having trouble getting all transactions since many are paginated. See here for an example where there are 14 tabs of transactions within the page. How can I get them all by extending the below code?

const list = [];

jQuery('div.uc-listingCard-content').each(function () {
const $this = jQuery(this);

list.push({
    'Name': $this.find('.uc-listingCard-titles > a').text().trim(),
    'City-State-Zip': $this.find('.uc-listingCard-titles > h2').text().trim(),
    'Price': $this.find('.uc-listingCard--priceGrid-sm > div').text().trim(),
    'Beds': $this.find('.uc-listingCard-subStat--beds').text().trim(),
    'Baths': $this.find('.uc-listingCard-subStat--baths').text().trim(),
});

});

console.log(list);

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

0

you can use console.log by JSON.stringify() for example:

console.log(JSON.stringify({ x: 5, y: 6 }));
// expected output: "{"x":5,"y":6}"

and for your code:

console.log(JSON.stringify(property))
about 4 years ago · Juan Pablo Isaza Relatório

0

You could write something like this using jQuery.

const list = [];

jQuery('div.uc-listingCard-content').each(function () {
    const $this = jQuery(this);

    list.push({
        'Name': $this.find('.uc-listingCard-titles > a').text().trim(),
        'City-State-Zip': $this.find('.uc-listingCard-titles > h2').text().trim(),
        'Price': $this.find('.uc-listingCard--priceGrid-sm > div').text().trim(),
        'Beds': $this.find('.uc-listingCard-subStat--beds').text().trim(),
        'Baths': $this.find('.uc-listingCard-subStat--baths').text().trim(),
    });

});

console.log(list);
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