Node.js cleaning, image conversion src & # 8594; full url

I use Cheerio (https://github.com/MatthewMueller/cheerio) to clean up websites and get images for the project I'm working on. I am wondering if there is an easy way with Node.js (or another package) to convert $ (img) .attr ('src') to a full URL? Sometimes I get "image.jpg" and other times "../../image.jpg", and sometimes "//somepath/image.jpg". Maybe I'm just missing some sort of regex ... Thanks for your time :)

+6
source share
1 answer

Take a look at the node url module. In particular, url.resolve(from, to) should be what you are looking for.

+9
source

All Articles