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

226
Visualizações
Get text from a specific class from a link

Using javascript, I'm trying to open a specific page, so I'm using window.open(). I want to search values and store them, values that are associated with a specific class. I have been searching a lot but I can't find out how to do that, I tried window.open(#link).getElementsByClassName but that doesn't work, nor link.querySelectorAll. Has anyone got any tips?

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

0

/* JavaScript */

class webpage {
  constructor(url) {
    this.url = url;
    this.frame = document.createElement("iframe");
    this.frame.setAttribute("style", "display: none; position: absolute; left: -99999px; top: -99999px;");
    document.body.appendChild(this.frame);
  }
  load() {
    return new Promise(function(resolve, reject) {
      var http = window.XMLHttpRequest?new XMLHttpRequest():new ActiveXObject("Microsoft.XMLHTTP");
      http.open("GET", this.url);
      http.addEventListener("load", function() {
        if(http.status == 200 && http.readyState == 4) {
          this.frame.contentWindow.document.write(http.responseText);
          resolve();
        } else if(http.readyState == 4) {
          reject(Error("Something went wrong"));
        }
      }.bind(this));
      http.addEventListener("error", function() {
        reject(Error("Something went wrong"));
      });
      http.send();
    }.bind(this));
  }
  get(query) {
    return (this.frame.contentWindow.document || this.frame.contentDocument).querySelectorAll(query);
  }
}

I have created a class called 'webpage'. For example, you can build your code like this:

/* JavaScript */

var page = new webpage("somepage.net/");// Only works for other domains if the CORS header 'Access-Control-Allow-Origin' is set
page.load().then(function(){
  var list = page.get("div.className"),
      element = list[0];
  alert(element.innerHTML);
});

however, it only works within your own domain or one for which 'Access-Control-Allow-Origin' is allowed. More about 'Access-Control-Allow-Origin' here.

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