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

214
Vistas
Get a part of html form external site

How can i get a part of the sorce code of a site for exampel if i would for say to ony want to get this part of code

<span class="definition">Anv&#228;nds n&#228;r man s&#228;ger hejd&#229; till n&#229;gon. Ha de G &#228;r samma sak som ha det bra, eller ha det g&#246;tt.</span><br /><br />

Form alot of code, and i want to do this in Javascript, and the code is comming from an external site, NAd this is node.js

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

The general technique you're talking about is called 'web scraping', and it can range from very simple to very complex. Assuming you're looking to do this in a node app (as your tags suggest), I'd suggest using the modules request and cheerio. If part of the html is generated by clientside javascript, this won't be sufficient, but you didn't indicate that in your question. Here's a pretty simple code snippet that describes what I'm suggesting:

const cheerio = require('cheerio');
const request = require('request');

request.get('http://example.com/index.html', (err, response, body) => {
   const $ = cheerio.load(body);

   const definitions = $('span.definition');
   console.log(definitions); // these are all selection result elements, you can do more with them here once you see what they contain. 
});
over 4 years ago · Santiago Trujillo Denunciar

0

You can use cheerio

const request = require("request");
const cheerio = require("cheerio");


request("http://example.com/some-uri", (err, response, body) => {

        if(err)
                throw err; //Handle error


        let $ = cheerio.load(body);

        let myElement = $('span.definition');

        console.log(myElement.html()); //Inner html
        console.log($.html(myElement)); //outer html


});
over 4 years ago · Santiago Trujillo 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