I’m using Cheerio (https://github.com/MatthewMueller/cheerio) to scrape websites and get images for a project I’m working on. I’m wondering if there’s an easy way with Node.js (or another package) to convert the $(img).attr(‘src’) to a fully qualified URL? Sometimes I’ll get “image.jpg” and other times “../../image.jpg”, and other times “//somepath/image.jpg”. Perhaps I’m just missing a regex of some sort… Thanks for your time 🙂
I’m using Cheerio (https://github.com/MatthewMueller/cheerio) to scrape websites and get images for a project I’m
Share
Look at the node
urlmodule. Specificallyurl.resolve(from, to)should be what you’re looking for.