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

270
Views
Cheerio js take all addresses that contain text only

I have the following code which takes me all the addresses.

I only need addresses that contain text.

Ex:

<a href="https://www...." target="_blank">Text...</a>

But the problem that there are addresses that contain an image, these addresses I would like to exclude them.

Ex:

<a href="http://www..." target="_blank"><img src="http://www." border="0" alt=""></a>

$("div#posts > div > div > div > div > table > tbody > tr:nth-child(2) > td:nth-child(2) > div:nth-child(3)").each((_idx, el) => {
     $(el).find('a').each((_idx, el) => {
         let u = $(el).attr('href')
         if(u.includes("http")) element.add(u);
      })
})

Can you give me a hand?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

try selecting a that does not have img (or maybe any children, if there are other elements), with combination of :has and :not

$(el).find('a:not(:has(img))').each((_idx, el) => {
    let u = $(el).attr('href')
    if (u.includes("http")) element.add(u);
})
about 4 years ago · Juan Pablo Isaza Report

0

You can use filter:

$('a').get().filter(a => $(a).text().match(/\w/)).map(a => $(a).attr('href'))
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!