0

I need to get absolute urls of links in a given url.To achieve this I use jquery and cheerio with browserify on javascript however prop("href") returns relative url instead of absolute.

const cheerio=request("cheerio");
let url=prompt("Enter url?");

 fetch(url)
.then(function (response) {
  return response.text();
})
.then(function (html) {
  
    const $=cheerio.load(html);

    $("a").each((index,value) =>
    {

    let href=$(value).prop("href");
    
    if(typeof href!=="undefined")
    {
      console.log(href);
    }

    });

});

I used "https://en.wikipedia.org/wiki/Flame" url to test the code.İf there is another way of getting absolute urls of all links in a given url using cheerio I would like to know.

To make it clear,first I get an url from the user.I then fetch the url and extract its html document with cheerio.I need to get all links in that html document with absolute urls so that I can fetch them later.However the props value does not give absolute url for all of the links.Some href attributes give absolute value while others give relative.

Utonyum
  • 51
  • 4

0 Answers0