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

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

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