I´m using the latest JSDOM package for Node.js and want to retrieve content from a website using the convenience api fromURL.
What do I want to achieve?
I want to retrieve the image src. After inspecting the DOM in my browser (chrome) the src attribute is set with a valid url (e.g. "http://some-url.com"). When using JSDOM to parse the dom the src attribute is only some base64 string of the image instead of the url.
The html code looks like this (simplified):
<body>
<div>
<picture>
<img src="http://some-url.com">
</picture>
</div>
</body>
In my setup I´ve also set the resources option, as JSDOM doesn´t load any subresources by default. Any hints what I´m currently missing?
const jsdom = require('jsdom');
const {JSDOM} = jsdom;
JSDOM.fromURL('url-link', { resources: "usable"}).then(dom => {
const image = dom.window.document.querySelector('img');
if (image) {
const src = image.src;
console.log('src: ', src); // e.g. data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20267%20400'%3E%3C/svg%3E
}
});