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

224
Views
Add space after each link in console

I am fetching all anchor tag links via web scraping and want to print all links with space between them so while console I used "\n" but it is not making space after end of first link and second link text start without space.

Code:

(async() => {
  const html = await axios.get('https://www.xyz');
  const $ = await cheerio.load(html.data);
  let data = []
  $(".div-previews").each((i, elem) => {
    console.log('data::', $(elem).find(".header-text a").text() + "\n"); // show links with space between them
  })();
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This should work better - I replaced your each and find

(async() => {
  const html = await axios.get('https://www.xyz');
  const $ = await cheerio.load(html.data);
  console.log('data::',
    $(".div-previews .header-text a")
    .map(function() { return this.textContent })
    .get()
    .join("\n") // or .join(" ")
  )
})

Example

console.log('data::',
  $(".div-previews .header-text a")
  .map(function() {
    return this.textContent
  })
  .get()
  .join("\n") // or .join(" ")
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<div class="div-previews">
  <div class="header-text">
    <a href="">Link 1</a>
  </div>
</div>
<div class="div-previews">
  <div class="header-text">
    <a href="">Link 2</a>
  </div>
</div>
<div class="div-previews">
  <div class="header-text">
    <a href="">Link 3</a>
    <a href="">Link 4</a>
  </div>
</div>

about 4 years ago · Juan Pablo Isaza 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!