Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!