How do I make a webpage think its images are done loading?
up vote
4
down vote
favorite
To give you some background, many (if not all) websites load their images one by one, so if there are a lot of images, and/or you have a slow computer, most of the images wont show up. This is avoidable for the most part, however if you're running a script to exact image URLs, then you don't need to see the image, you just want its URL. My question is as follows:
Is it possible to trick a webpage into thinking an image is done loading so that it will start loading the next one?
javascript image loading
add a comment |
up vote
4
down vote
favorite
To give you some background, many (if not all) websites load their images one by one, so if there are a lot of images, and/or you have a slow computer, most of the images wont show up. This is avoidable for the most part, however if you're running a script to exact image URLs, then you don't need to see the image, you just want its URL. My question is as follows:
Is it possible to trick a webpage into thinking an image is done loading so that it will start loading the next one?
javascript image loading
You should scrape only the web page HTML and load it in a DOM parser utility. This should be done in a command line application and not in browser...
– Niloct
Nov 5 at 19:28
What is the purpose? Do you want the images take the place it should take even if it didn't yet completely load?
– A. Meshu
Nov 5 at 19:32
I want to extract the image URLs into a text file.
– Jack Kasbrack
Nov 5 at 20:20
This doesn't make much sense. Can you provide the link to the website in question?
– Unglückspilz
Nov 12 at 11:50
add a comment |
up vote
4
down vote
favorite
up vote
4
down vote
favorite
To give you some background, many (if not all) websites load their images one by one, so if there are a lot of images, and/or you have a slow computer, most of the images wont show up. This is avoidable for the most part, however if you're running a script to exact image URLs, then you don't need to see the image, you just want its URL. My question is as follows:
Is it possible to trick a webpage into thinking an image is done loading so that it will start loading the next one?
javascript image loading
To give you some background, many (if not all) websites load their images one by one, so if there are a lot of images, and/or you have a slow computer, most of the images wont show up. This is avoidable for the most part, however if you're running a script to exact image URLs, then you don't need to see the image, you just want its URL. My question is as follows:
Is it possible to trick a webpage into thinking an image is done loading so that it will start loading the next one?
javascript image loading
javascript image loading
asked Nov 5 at 19:03
Jack Kasbrack
13814
13814
You should scrape only the web page HTML and load it in a DOM parser utility. This should be done in a command line application and not in browser...
– Niloct
Nov 5 at 19:28
What is the purpose? Do you want the images take the place it should take even if it didn't yet completely load?
– A. Meshu
Nov 5 at 19:32
I want to extract the image URLs into a text file.
– Jack Kasbrack
Nov 5 at 20:20
This doesn't make much sense. Can you provide the link to the website in question?
– Unglückspilz
Nov 12 at 11:50
add a comment |
You should scrape only the web page HTML and load it in a DOM parser utility. This should be done in a command line application and not in browser...
– Niloct
Nov 5 at 19:28
What is the purpose? Do you want the images take the place it should take even if it didn't yet completely load?
– A. Meshu
Nov 5 at 19:32
I want to extract the image URLs into a text file.
– Jack Kasbrack
Nov 5 at 20:20
This doesn't make much sense. Can you provide the link to the website in question?
– Unglückspilz
Nov 12 at 11:50
You should scrape only the web page HTML and load it in a DOM parser utility. This should be done in a command line application and not in browser...
– Niloct
Nov 5 at 19:28
You should scrape only the web page HTML and load it in a DOM parser utility. This should be done in a command line application and not in browser...
– Niloct
Nov 5 at 19:28
What is the purpose? Do you want the images take the place it should take even if it didn't yet completely load?
– A. Meshu
Nov 5 at 19:32
What is the purpose? Do you want the images take the place it should take even if it didn't yet completely load?
– A. Meshu
Nov 5 at 19:32
I want to extract the image URLs into a text file.
– Jack Kasbrack
Nov 5 at 20:20
I want to extract the image URLs into a text file.
– Jack Kasbrack
Nov 5 at 20:20
This doesn't make much sense. Can you provide the link to the website in question?
– Unglückspilz
Nov 12 at 11:50
This doesn't make much sense. Can you provide the link to the website in question?
– Unglückspilz
Nov 12 at 11:50
add a comment |
6 Answers
6
active
oldest
votes
up vote
1
down vote
accepted
use a plugin called lazy load. what it does is it will load the whole webpage and will just load the image later on. it will only load the image when the user scroll on it.
do you have a link?
– Jack Kasbrack
Nov 17 at 22:41
check this link, ive used it before, very simple to implement: jquery.eisbehr.de/lazy
– kapitan
Nov 18 at 11:41
is this a chrome extension? how do I set it up?
– Jack Kasbrack
Nov 18 at 17:57
you just have to download and include the js file (jquery.lazy.min.js) on your webpage, then give all of your images a class (example: <img src='' class='lazyimg' />) then put this inside the script tag $(function() { $('.lazyimg').lazy(); }); - you also need jquery of course =)
– kapitan
Nov 19 at 1:03
1
oh, apologies, now i understand. then you should use the Chrome extension i am using for that exact purpose. search for "Text Mode", it's a google chrome extension. what it does is that it simply doesnt load any images of any webpage. i used this at work so that i can browse any website more safely.
– kapitan
Nov 21 at 0:17
|
show 3 more comments
up vote
5
down vote
Typically browser will not wait for one image to be downloaded before requesting the next image. It will request all images simultaneously, as soon as it gets the src
s of those images.
Are you sure that the images are indeed waiting for previous image to download or are they waiting for a specific time interval?
In case if you are sure that it depends on download of previous image, then what you can do is, route all your requests through some proxy server / firewall and configure it to return an empty file with HTTP status 200 whenever an image is requested from that site.
That way the browser (or actually the website code) will assume that it has downloaded the image successfully.
how do I do that? – Jack Kasbrack
That's actually a very open ended / opinion based question. It will also depend on your OS, browser, system permissions etc. Assuming you are using Windows and have sufficient permissions, you can try using Fiddler. It has an AutoResponder functionality that you can use.
(I've no affiliation with Fiddler / Telerik as such. I'm suggesting it only as an example and because I've used it in the past and know that it can be used for the aforementioned purpose. There will be many more products that provide similar functionality and you should use the product of your choice.)
how do I do that?
– Jack Kasbrack
Nov 12 at 15:48
1
@JackKasbrack Updated my answer.
– Vivek Athalye
Nov 13 at 15:53
Okay, I will try it tomorrow. Thank you for your time.
– Jack Kasbrack
Nov 14 at 2:19
it didn't work.
– Jack Kasbrack
Nov 15 at 14:33
add a comment |
up vote
0
down vote
To extract all image URLs to a text file maybe you could use something like this,
If you execute this script inside any website it will list the URLs of the images
document.querySelectorAll('*[src]').forEach((item) => {
const isImage = item.src.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (isImage) console.log(item.src);
});
You could also use the same idea to read Style from elements and get images from background url or something, like that:
document.querySelectorAll('*').forEach((item) => {
const computedItem = getComputedStyle(item);
Object.keys(computedItem).forEach((attr) => {
const style = computedItem[attr];
const image = style.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (image) console.log(image[0]);
});
});
So, at the end of the day you could do some function like that, which will return an array of all images on the site
function getImageURLS() {
let images = ;
document.querySelectorAll('*').forEach((item) => {
const computedItem = getComputedStyle(item);
Object.keys(computedItem).forEach((attr) => {
const style = computedItem[attr];
const image = style.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (image) images.push(image[0]);
});
});
document.querySelectorAll('*[src]').forEach((item) => {
const isImage = item.src.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (isImage) images.push(item.src);
});
return images;
}
It can probably be optimized but, well you get the idea..
The issue is that the site I'm trying to get the images from doesn't load an image or it's URL until the previous one is done loading. I'm looking for a way to make the site think it's images are done loading, so that I can keep all the image URLs.
– Jack Kasbrack
Nov 11 at 21:22
yes, I get the idea, but if I try to run this code, or similar code before the page is done loading, I get a file called blank.gif.
– Jack Kasbrack
Nov 13 at 17:04
add a comment |
up vote
0
down vote
If you just want to extract images once. You can use some tools like
1) Chrome Extension
2) Software
3) Online website
If you want to run it multiple times. Probably use the above code https://stackoverflow.com/a/53245330/4674358 wrapped in if condition
if(document.readyState === "complete") {
extractURL();
}
else {
//Add onload or DOMContentLoaded event listeners here: for example,
window.addEventListener("onload", function () {
extractURL();
}, false);
//or
/*document.addEventListener("DOMContentLoaded", function () {
extractURL();
}, false);*/
}
extractURL() {
//code mentioned above
}
I created my own chrome extension to do it. The problem is that you can't extract images that aren't loaded
– Jack Kasbrack
Nov 15 at 23:45
1
You can very well get the full DOM in chrome extension. then parse it and load urls using above code.There is no need to wait for images to download. Check out stackoverflow.com/a/7641233/4674358
– Shubham
Nov 16 at 0:08
add a comment |
up vote
0
down vote
You want the "DOMContentLoaded" event docs. It fires as soon as the document is fully parsed, but before everything has been loaded.
let addIfImage = (list, image) => image.src.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g) ?
[image.src, ...list] :
list;
let getSrcFromTags= (tag = 'img') => Array.from(document.getElementsByTagName(tag))
.reduce(addIfImage, );
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", doSomething);
} else { // `DOMContentLoaded` already fired
doSomething();
}
okay, I'll try that.
– Jack Kasbrack
Nov 16 at 14:34
nope. Still getting "blank.gif"
– Jack Kasbrack
Nov 18 at 21:38
add a comment |
up vote
0
down vote
I am using this, works as expected:
var imageLoading = function(n) {
var image = document.images[n];
var downloadingImage = new Image();
downloadingImage.onload = function(){
image.src = this.src;
console.log('Image ' + n + ' loaded');
if (document.images[++n]) {
imageLoading(n);
}
};
downloadingImage.src = image.getAttribute("data-src");
}
document.addEventListener("DOMContentLoaded", function(event) {
setTimeout(function() {
imageLoading(0);
}, 0);
});
And change every src
attribute of image element to data-src
data-src is undefined
– Jack Kasbrack
Nov 18 at 21:44
Have you changed every src attribute of image element to data-src and is filled ?
– ribrow
Nov 20 at 13:18
none of them have a data-src attribute
– Jack Kasbrack
Nov 20 at 14:25
I said change them, or more specifically replace them...
– ribrow
Nov 20 at 15:30
There''s nothing to replace, it doesn't exist. Do I just add it?
– Jack Kasbrack
Nov 20 at 18:05
add a comment |
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
use a plugin called lazy load. what it does is it will load the whole webpage and will just load the image later on. it will only load the image when the user scroll on it.
do you have a link?
– Jack Kasbrack
Nov 17 at 22:41
check this link, ive used it before, very simple to implement: jquery.eisbehr.de/lazy
– kapitan
Nov 18 at 11:41
is this a chrome extension? how do I set it up?
– Jack Kasbrack
Nov 18 at 17:57
you just have to download and include the js file (jquery.lazy.min.js) on your webpage, then give all of your images a class (example: <img src='' class='lazyimg' />) then put this inside the script tag $(function() { $('.lazyimg').lazy(); }); - you also need jquery of course =)
– kapitan
Nov 19 at 1:03
1
oh, apologies, now i understand. then you should use the Chrome extension i am using for that exact purpose. search for "Text Mode", it's a google chrome extension. what it does is that it simply doesnt load any images of any webpage. i used this at work so that i can browse any website more safely.
– kapitan
Nov 21 at 0:17
|
show 3 more comments
up vote
1
down vote
accepted
use a plugin called lazy load. what it does is it will load the whole webpage and will just load the image later on. it will only load the image when the user scroll on it.
do you have a link?
– Jack Kasbrack
Nov 17 at 22:41
check this link, ive used it before, very simple to implement: jquery.eisbehr.de/lazy
– kapitan
Nov 18 at 11:41
is this a chrome extension? how do I set it up?
– Jack Kasbrack
Nov 18 at 17:57
you just have to download and include the js file (jquery.lazy.min.js) on your webpage, then give all of your images a class (example: <img src='' class='lazyimg' />) then put this inside the script tag $(function() { $('.lazyimg').lazy(); }); - you also need jquery of course =)
– kapitan
Nov 19 at 1:03
1
oh, apologies, now i understand. then you should use the Chrome extension i am using for that exact purpose. search for "Text Mode", it's a google chrome extension. what it does is that it simply doesnt load any images of any webpage. i used this at work so that i can browse any website more safely.
– kapitan
Nov 21 at 0:17
|
show 3 more comments
up vote
1
down vote
accepted
up vote
1
down vote
accepted
use a plugin called lazy load. what it does is it will load the whole webpage and will just load the image later on. it will only load the image when the user scroll on it.
use a plugin called lazy load. what it does is it will load the whole webpage and will just load the image later on. it will only load the image when the user scroll on it.
answered Nov 17 at 14:28
kapitan
31819
31819
do you have a link?
– Jack Kasbrack
Nov 17 at 22:41
check this link, ive used it before, very simple to implement: jquery.eisbehr.de/lazy
– kapitan
Nov 18 at 11:41
is this a chrome extension? how do I set it up?
– Jack Kasbrack
Nov 18 at 17:57
you just have to download and include the js file (jquery.lazy.min.js) on your webpage, then give all of your images a class (example: <img src='' class='lazyimg' />) then put this inside the script tag $(function() { $('.lazyimg').lazy(); }); - you also need jquery of course =)
– kapitan
Nov 19 at 1:03
1
oh, apologies, now i understand. then you should use the Chrome extension i am using for that exact purpose. search for "Text Mode", it's a google chrome extension. what it does is that it simply doesnt load any images of any webpage. i used this at work so that i can browse any website more safely.
– kapitan
Nov 21 at 0:17
|
show 3 more comments
do you have a link?
– Jack Kasbrack
Nov 17 at 22:41
check this link, ive used it before, very simple to implement: jquery.eisbehr.de/lazy
– kapitan
Nov 18 at 11:41
is this a chrome extension? how do I set it up?
– Jack Kasbrack
Nov 18 at 17:57
you just have to download and include the js file (jquery.lazy.min.js) on your webpage, then give all of your images a class (example: <img src='' class='lazyimg' />) then put this inside the script tag $(function() { $('.lazyimg').lazy(); }); - you also need jquery of course =)
– kapitan
Nov 19 at 1:03
1
oh, apologies, now i understand. then you should use the Chrome extension i am using for that exact purpose. search for "Text Mode", it's a google chrome extension. what it does is that it simply doesnt load any images of any webpage. i used this at work so that i can browse any website more safely.
– kapitan
Nov 21 at 0:17
do you have a link?
– Jack Kasbrack
Nov 17 at 22:41
do you have a link?
– Jack Kasbrack
Nov 17 at 22:41
check this link, ive used it before, very simple to implement: jquery.eisbehr.de/lazy
– kapitan
Nov 18 at 11:41
check this link, ive used it before, very simple to implement: jquery.eisbehr.de/lazy
– kapitan
Nov 18 at 11:41
is this a chrome extension? how do I set it up?
– Jack Kasbrack
Nov 18 at 17:57
is this a chrome extension? how do I set it up?
– Jack Kasbrack
Nov 18 at 17:57
you just have to download and include the js file (jquery.lazy.min.js) on your webpage, then give all of your images a class (example: <img src='' class='lazyimg' />) then put this inside the script tag $(function() { $('.lazyimg').lazy(); }); - you also need jquery of course =)
– kapitan
Nov 19 at 1:03
you just have to download and include the js file (jquery.lazy.min.js) on your webpage, then give all of your images a class (example: <img src='' class='lazyimg' />) then put this inside the script tag $(function() { $('.lazyimg').lazy(); }); - you also need jquery of course =)
– kapitan
Nov 19 at 1:03
1
1
oh, apologies, now i understand. then you should use the Chrome extension i am using for that exact purpose. search for "Text Mode", it's a google chrome extension. what it does is that it simply doesnt load any images of any webpage. i used this at work so that i can browse any website more safely.
– kapitan
Nov 21 at 0:17
oh, apologies, now i understand. then you should use the Chrome extension i am using for that exact purpose. search for "Text Mode", it's a google chrome extension. what it does is that it simply doesnt load any images of any webpage. i used this at work so that i can browse any website more safely.
– kapitan
Nov 21 at 0:17
|
show 3 more comments
up vote
5
down vote
Typically browser will not wait for one image to be downloaded before requesting the next image. It will request all images simultaneously, as soon as it gets the src
s of those images.
Are you sure that the images are indeed waiting for previous image to download or are they waiting for a specific time interval?
In case if you are sure that it depends on download of previous image, then what you can do is, route all your requests through some proxy server / firewall and configure it to return an empty file with HTTP status 200 whenever an image is requested from that site.
That way the browser (or actually the website code) will assume that it has downloaded the image successfully.
how do I do that? – Jack Kasbrack
That's actually a very open ended / opinion based question. It will also depend on your OS, browser, system permissions etc. Assuming you are using Windows and have sufficient permissions, you can try using Fiddler. It has an AutoResponder functionality that you can use.
(I've no affiliation with Fiddler / Telerik as such. I'm suggesting it only as an example and because I've used it in the past and know that it can be used for the aforementioned purpose. There will be many more products that provide similar functionality and you should use the product of your choice.)
how do I do that?
– Jack Kasbrack
Nov 12 at 15:48
1
@JackKasbrack Updated my answer.
– Vivek Athalye
Nov 13 at 15:53
Okay, I will try it tomorrow. Thank you for your time.
– Jack Kasbrack
Nov 14 at 2:19
it didn't work.
– Jack Kasbrack
Nov 15 at 14:33
add a comment |
up vote
5
down vote
Typically browser will not wait for one image to be downloaded before requesting the next image. It will request all images simultaneously, as soon as it gets the src
s of those images.
Are you sure that the images are indeed waiting for previous image to download or are they waiting for a specific time interval?
In case if you are sure that it depends on download of previous image, then what you can do is, route all your requests through some proxy server / firewall and configure it to return an empty file with HTTP status 200 whenever an image is requested from that site.
That way the browser (or actually the website code) will assume that it has downloaded the image successfully.
how do I do that? – Jack Kasbrack
That's actually a very open ended / opinion based question. It will also depend on your OS, browser, system permissions etc. Assuming you are using Windows and have sufficient permissions, you can try using Fiddler. It has an AutoResponder functionality that you can use.
(I've no affiliation with Fiddler / Telerik as such. I'm suggesting it only as an example and because I've used it in the past and know that it can be used for the aforementioned purpose. There will be many more products that provide similar functionality and you should use the product of your choice.)
how do I do that?
– Jack Kasbrack
Nov 12 at 15:48
1
@JackKasbrack Updated my answer.
– Vivek Athalye
Nov 13 at 15:53
Okay, I will try it tomorrow. Thank you for your time.
– Jack Kasbrack
Nov 14 at 2:19
it didn't work.
– Jack Kasbrack
Nov 15 at 14:33
add a comment |
up vote
5
down vote
up vote
5
down vote
Typically browser will not wait for one image to be downloaded before requesting the next image. It will request all images simultaneously, as soon as it gets the src
s of those images.
Are you sure that the images are indeed waiting for previous image to download or are they waiting for a specific time interval?
In case if you are sure that it depends on download of previous image, then what you can do is, route all your requests through some proxy server / firewall and configure it to return an empty file with HTTP status 200 whenever an image is requested from that site.
That way the browser (or actually the website code) will assume that it has downloaded the image successfully.
how do I do that? – Jack Kasbrack
That's actually a very open ended / opinion based question. It will also depend on your OS, browser, system permissions etc. Assuming you are using Windows and have sufficient permissions, you can try using Fiddler. It has an AutoResponder functionality that you can use.
(I've no affiliation with Fiddler / Telerik as such. I'm suggesting it only as an example and because I've used it in the past and know that it can be used for the aforementioned purpose. There will be many more products that provide similar functionality and you should use the product of your choice.)
Typically browser will not wait for one image to be downloaded before requesting the next image. It will request all images simultaneously, as soon as it gets the src
s of those images.
Are you sure that the images are indeed waiting for previous image to download or are they waiting for a specific time interval?
In case if you are sure that it depends on download of previous image, then what you can do is, route all your requests through some proxy server / firewall and configure it to return an empty file with HTTP status 200 whenever an image is requested from that site.
That way the browser (or actually the website code) will assume that it has downloaded the image successfully.
how do I do that? – Jack Kasbrack
That's actually a very open ended / opinion based question. It will also depend on your OS, browser, system permissions etc. Assuming you are using Windows and have sufficient permissions, you can try using Fiddler. It has an AutoResponder functionality that you can use.
(I've no affiliation with Fiddler / Telerik as such. I'm suggesting it only as an example and because I've used it in the past and know that it can be used for the aforementioned purpose. There will be many more products that provide similar functionality and you should use the product of your choice.)
edited Nov 13 at 15:52
answered Nov 12 at 15:45
Vivek Athalye
2,50611629
2,50611629
how do I do that?
– Jack Kasbrack
Nov 12 at 15:48
1
@JackKasbrack Updated my answer.
– Vivek Athalye
Nov 13 at 15:53
Okay, I will try it tomorrow. Thank you for your time.
– Jack Kasbrack
Nov 14 at 2:19
it didn't work.
– Jack Kasbrack
Nov 15 at 14:33
add a comment |
how do I do that?
– Jack Kasbrack
Nov 12 at 15:48
1
@JackKasbrack Updated my answer.
– Vivek Athalye
Nov 13 at 15:53
Okay, I will try it tomorrow. Thank you for your time.
– Jack Kasbrack
Nov 14 at 2:19
it didn't work.
– Jack Kasbrack
Nov 15 at 14:33
how do I do that?
– Jack Kasbrack
Nov 12 at 15:48
how do I do that?
– Jack Kasbrack
Nov 12 at 15:48
1
1
@JackKasbrack Updated my answer.
– Vivek Athalye
Nov 13 at 15:53
@JackKasbrack Updated my answer.
– Vivek Athalye
Nov 13 at 15:53
Okay, I will try it tomorrow. Thank you for your time.
– Jack Kasbrack
Nov 14 at 2:19
Okay, I will try it tomorrow. Thank you for your time.
– Jack Kasbrack
Nov 14 at 2:19
it didn't work.
– Jack Kasbrack
Nov 15 at 14:33
it didn't work.
– Jack Kasbrack
Nov 15 at 14:33
add a comment |
up vote
0
down vote
To extract all image URLs to a text file maybe you could use something like this,
If you execute this script inside any website it will list the URLs of the images
document.querySelectorAll('*[src]').forEach((item) => {
const isImage = item.src.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (isImage) console.log(item.src);
});
You could also use the same idea to read Style from elements and get images from background url or something, like that:
document.querySelectorAll('*').forEach((item) => {
const computedItem = getComputedStyle(item);
Object.keys(computedItem).forEach((attr) => {
const style = computedItem[attr];
const image = style.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (image) console.log(image[0]);
});
});
So, at the end of the day you could do some function like that, which will return an array of all images on the site
function getImageURLS() {
let images = ;
document.querySelectorAll('*').forEach((item) => {
const computedItem = getComputedStyle(item);
Object.keys(computedItem).forEach((attr) => {
const style = computedItem[attr];
const image = style.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (image) images.push(image[0]);
});
});
document.querySelectorAll('*[src]').forEach((item) => {
const isImage = item.src.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (isImage) images.push(item.src);
});
return images;
}
It can probably be optimized but, well you get the idea..
The issue is that the site I'm trying to get the images from doesn't load an image or it's URL until the previous one is done loading. I'm looking for a way to make the site think it's images are done loading, so that I can keep all the image URLs.
– Jack Kasbrack
Nov 11 at 21:22
yes, I get the idea, but if I try to run this code, or similar code before the page is done loading, I get a file called blank.gif.
– Jack Kasbrack
Nov 13 at 17:04
add a comment |
up vote
0
down vote
To extract all image URLs to a text file maybe you could use something like this,
If you execute this script inside any website it will list the URLs of the images
document.querySelectorAll('*[src]').forEach((item) => {
const isImage = item.src.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (isImage) console.log(item.src);
});
You could also use the same idea to read Style from elements and get images from background url or something, like that:
document.querySelectorAll('*').forEach((item) => {
const computedItem = getComputedStyle(item);
Object.keys(computedItem).forEach((attr) => {
const style = computedItem[attr];
const image = style.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (image) console.log(image[0]);
});
});
So, at the end of the day you could do some function like that, which will return an array of all images on the site
function getImageURLS() {
let images = ;
document.querySelectorAll('*').forEach((item) => {
const computedItem = getComputedStyle(item);
Object.keys(computedItem).forEach((attr) => {
const style = computedItem[attr];
const image = style.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (image) images.push(image[0]);
});
});
document.querySelectorAll('*[src]').forEach((item) => {
const isImage = item.src.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (isImage) images.push(item.src);
});
return images;
}
It can probably be optimized but, well you get the idea..
The issue is that the site I'm trying to get the images from doesn't load an image or it's URL until the previous one is done loading. I'm looking for a way to make the site think it's images are done loading, so that I can keep all the image URLs.
– Jack Kasbrack
Nov 11 at 21:22
yes, I get the idea, but if I try to run this code, or similar code before the page is done loading, I get a file called blank.gif.
– Jack Kasbrack
Nov 13 at 17:04
add a comment |
up vote
0
down vote
up vote
0
down vote
To extract all image URLs to a text file maybe you could use something like this,
If you execute this script inside any website it will list the URLs of the images
document.querySelectorAll('*[src]').forEach((item) => {
const isImage = item.src.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (isImage) console.log(item.src);
});
You could also use the same idea to read Style from elements and get images from background url or something, like that:
document.querySelectorAll('*').forEach((item) => {
const computedItem = getComputedStyle(item);
Object.keys(computedItem).forEach((attr) => {
const style = computedItem[attr];
const image = style.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (image) console.log(image[0]);
});
});
So, at the end of the day you could do some function like that, which will return an array of all images on the site
function getImageURLS() {
let images = ;
document.querySelectorAll('*').forEach((item) => {
const computedItem = getComputedStyle(item);
Object.keys(computedItem).forEach((attr) => {
const style = computedItem[attr];
const image = style.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (image) images.push(image[0]);
});
});
document.querySelectorAll('*[src]').forEach((item) => {
const isImage = item.src.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (isImage) images.push(item.src);
});
return images;
}
It can probably be optimized but, well you get the idea..
To extract all image URLs to a text file maybe you could use something like this,
If you execute this script inside any website it will list the URLs of the images
document.querySelectorAll('*[src]').forEach((item) => {
const isImage = item.src.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (isImage) console.log(item.src);
});
You could also use the same idea to read Style from elements and get images from background url or something, like that:
document.querySelectorAll('*').forEach((item) => {
const computedItem = getComputedStyle(item);
Object.keys(computedItem).forEach((attr) => {
const style = computedItem[attr];
const image = style.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (image) console.log(image[0]);
});
});
So, at the end of the day you could do some function like that, which will return an array of all images on the site
function getImageURLS() {
let images = ;
document.querySelectorAll('*').forEach((item) => {
const computedItem = getComputedStyle(item);
Object.keys(computedItem).forEach((attr) => {
const style = computedItem[attr];
const image = style.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (image) images.push(image[0]);
});
});
document.querySelectorAll('*[src]').forEach((item) => {
const isImage = item.src.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g);
if (isImage) images.push(item.src);
});
return images;
}
It can probably be optimized but, well you get the idea..
edited Nov 11 at 2:52
answered Nov 11 at 2:27
el Corleone
11
11
The issue is that the site I'm trying to get the images from doesn't load an image or it's URL until the previous one is done loading. I'm looking for a way to make the site think it's images are done loading, so that I can keep all the image URLs.
– Jack Kasbrack
Nov 11 at 21:22
yes, I get the idea, but if I try to run this code, or similar code before the page is done loading, I get a file called blank.gif.
– Jack Kasbrack
Nov 13 at 17:04
add a comment |
The issue is that the site I'm trying to get the images from doesn't load an image or it's URL until the previous one is done loading. I'm looking for a way to make the site think it's images are done loading, so that I can keep all the image URLs.
– Jack Kasbrack
Nov 11 at 21:22
yes, I get the idea, but if I try to run this code, or similar code before the page is done loading, I get a file called blank.gif.
– Jack Kasbrack
Nov 13 at 17:04
The issue is that the site I'm trying to get the images from doesn't load an image or it's URL until the previous one is done loading. I'm looking for a way to make the site think it's images are done loading, so that I can keep all the image URLs.
– Jack Kasbrack
Nov 11 at 21:22
The issue is that the site I'm trying to get the images from doesn't load an image or it's URL until the previous one is done loading. I'm looking for a way to make the site think it's images are done loading, so that I can keep all the image URLs.
– Jack Kasbrack
Nov 11 at 21:22
yes, I get the idea, but if I try to run this code, or similar code before the page is done loading, I get a file called blank.gif.
– Jack Kasbrack
Nov 13 at 17:04
yes, I get the idea, but if I try to run this code, or similar code before the page is done loading, I get a file called blank.gif.
– Jack Kasbrack
Nov 13 at 17:04
add a comment |
up vote
0
down vote
If you just want to extract images once. You can use some tools like
1) Chrome Extension
2) Software
3) Online website
If you want to run it multiple times. Probably use the above code https://stackoverflow.com/a/53245330/4674358 wrapped in if condition
if(document.readyState === "complete") {
extractURL();
}
else {
//Add onload or DOMContentLoaded event listeners here: for example,
window.addEventListener("onload", function () {
extractURL();
}, false);
//or
/*document.addEventListener("DOMContentLoaded", function () {
extractURL();
}, false);*/
}
extractURL() {
//code mentioned above
}
I created my own chrome extension to do it. The problem is that you can't extract images that aren't loaded
– Jack Kasbrack
Nov 15 at 23:45
1
You can very well get the full DOM in chrome extension. then parse it and load urls using above code.There is no need to wait for images to download. Check out stackoverflow.com/a/7641233/4674358
– Shubham
Nov 16 at 0:08
add a comment |
up vote
0
down vote
If you just want to extract images once. You can use some tools like
1) Chrome Extension
2) Software
3) Online website
If you want to run it multiple times. Probably use the above code https://stackoverflow.com/a/53245330/4674358 wrapped in if condition
if(document.readyState === "complete") {
extractURL();
}
else {
//Add onload or DOMContentLoaded event listeners here: for example,
window.addEventListener("onload", function () {
extractURL();
}, false);
//or
/*document.addEventListener("DOMContentLoaded", function () {
extractURL();
}, false);*/
}
extractURL() {
//code mentioned above
}
I created my own chrome extension to do it. The problem is that you can't extract images that aren't loaded
– Jack Kasbrack
Nov 15 at 23:45
1
You can very well get the full DOM in chrome extension. then parse it and load urls using above code.There is no need to wait for images to download. Check out stackoverflow.com/a/7641233/4674358
– Shubham
Nov 16 at 0:08
add a comment |
up vote
0
down vote
up vote
0
down vote
If you just want to extract images once. You can use some tools like
1) Chrome Extension
2) Software
3) Online website
If you want to run it multiple times. Probably use the above code https://stackoverflow.com/a/53245330/4674358 wrapped in if condition
if(document.readyState === "complete") {
extractURL();
}
else {
//Add onload or DOMContentLoaded event listeners here: for example,
window.addEventListener("onload", function () {
extractURL();
}, false);
//or
/*document.addEventListener("DOMContentLoaded", function () {
extractURL();
}, false);*/
}
extractURL() {
//code mentioned above
}
If you just want to extract images once. You can use some tools like
1) Chrome Extension
2) Software
3) Online website
If you want to run it multiple times. Probably use the above code https://stackoverflow.com/a/53245330/4674358 wrapped in if condition
if(document.readyState === "complete") {
extractURL();
}
else {
//Add onload or DOMContentLoaded event listeners here: for example,
window.addEventListener("onload", function () {
extractURL();
}, false);
//or
/*document.addEventListener("DOMContentLoaded", function () {
extractURL();
}, false);*/
}
extractURL() {
//code mentioned above
}
if(document.readyState === "complete") {
extractURL();
}
else {
//Add onload or DOMContentLoaded event listeners here: for example,
window.addEventListener("onload", function () {
extractURL();
}, false);
//or
/*document.addEventListener("DOMContentLoaded", function () {
extractURL();
}, false);*/
}
extractURL() {
//code mentioned above
}
if(document.readyState === "complete") {
extractURL();
}
else {
//Add onload or DOMContentLoaded event listeners here: for example,
window.addEventListener("onload", function () {
extractURL();
}, false);
//or
/*document.addEventListener("DOMContentLoaded", function () {
extractURL();
}, false);*/
}
extractURL() {
//code mentioned above
}
answered Nov 15 at 23:01
Shubham
852622
852622
I created my own chrome extension to do it. The problem is that you can't extract images that aren't loaded
– Jack Kasbrack
Nov 15 at 23:45
1
You can very well get the full DOM in chrome extension. then parse it and load urls using above code.There is no need to wait for images to download. Check out stackoverflow.com/a/7641233/4674358
– Shubham
Nov 16 at 0:08
add a comment |
I created my own chrome extension to do it. The problem is that you can't extract images that aren't loaded
– Jack Kasbrack
Nov 15 at 23:45
1
You can very well get the full DOM in chrome extension. then parse it and load urls using above code.There is no need to wait for images to download. Check out stackoverflow.com/a/7641233/4674358
– Shubham
Nov 16 at 0:08
I created my own chrome extension to do it. The problem is that you can't extract images that aren't loaded
– Jack Kasbrack
Nov 15 at 23:45
I created my own chrome extension to do it. The problem is that you can't extract images that aren't loaded
– Jack Kasbrack
Nov 15 at 23:45
1
1
You can very well get the full DOM in chrome extension. then parse it and load urls using above code.There is no need to wait for images to download. Check out stackoverflow.com/a/7641233/4674358
– Shubham
Nov 16 at 0:08
You can very well get the full DOM in chrome extension. then parse it and load urls using above code.There is no need to wait for images to download. Check out stackoverflow.com/a/7641233/4674358
– Shubham
Nov 16 at 0:08
add a comment |
up vote
0
down vote
You want the "DOMContentLoaded" event docs. It fires as soon as the document is fully parsed, but before everything has been loaded.
let addIfImage = (list, image) => image.src.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g) ?
[image.src, ...list] :
list;
let getSrcFromTags= (tag = 'img') => Array.from(document.getElementsByTagName(tag))
.reduce(addIfImage, );
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", doSomething);
} else { // `DOMContentLoaded` already fired
doSomething();
}
okay, I'll try that.
– Jack Kasbrack
Nov 16 at 14:34
nope. Still getting "blank.gif"
– Jack Kasbrack
Nov 18 at 21:38
add a comment |
up vote
0
down vote
You want the "DOMContentLoaded" event docs. It fires as soon as the document is fully parsed, but before everything has been loaded.
let addIfImage = (list, image) => image.src.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g) ?
[image.src, ...list] :
list;
let getSrcFromTags= (tag = 'img') => Array.from(document.getElementsByTagName(tag))
.reduce(addIfImage, );
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", doSomething);
} else { // `DOMContentLoaded` already fired
doSomething();
}
okay, I'll try that.
– Jack Kasbrack
Nov 16 at 14:34
nope. Still getting "blank.gif"
– Jack Kasbrack
Nov 18 at 21:38
add a comment |
up vote
0
down vote
up vote
0
down vote
You want the "DOMContentLoaded" event docs. It fires as soon as the document is fully parsed, but before everything has been loaded.
let addIfImage = (list, image) => image.src.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g) ?
[image.src, ...list] :
list;
let getSrcFromTags= (tag = 'img') => Array.from(document.getElementsByTagName(tag))
.reduce(addIfImage, );
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", doSomething);
} else { // `DOMContentLoaded` already fired
doSomething();
}
You want the "DOMContentLoaded" event docs. It fires as soon as the document is fully parsed, but before everything has been loaded.
let addIfImage = (list, image) => image.src.match(/(http(s?):)([/|.|w|s|-])*.(?:jpg|jpeg|gif|png|svg)/g) ?
[image.src, ...list] :
list;
let getSrcFromTags= (tag = 'img') => Array.from(document.getElementsByTagName(tag))
.reduce(addIfImage, );
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", doSomething);
} else { // `DOMContentLoaded` already fired
doSomething();
}
edited Nov 16 at 7:33
answered Nov 16 at 7:27
Malisbad
543
543
okay, I'll try that.
– Jack Kasbrack
Nov 16 at 14:34
nope. Still getting "blank.gif"
– Jack Kasbrack
Nov 18 at 21:38
add a comment |
okay, I'll try that.
– Jack Kasbrack
Nov 16 at 14:34
nope. Still getting "blank.gif"
– Jack Kasbrack
Nov 18 at 21:38
okay, I'll try that.
– Jack Kasbrack
Nov 16 at 14:34
okay, I'll try that.
– Jack Kasbrack
Nov 16 at 14:34
nope. Still getting "blank.gif"
– Jack Kasbrack
Nov 18 at 21:38
nope. Still getting "blank.gif"
– Jack Kasbrack
Nov 18 at 21:38
add a comment |
up vote
0
down vote
I am using this, works as expected:
var imageLoading = function(n) {
var image = document.images[n];
var downloadingImage = new Image();
downloadingImage.onload = function(){
image.src = this.src;
console.log('Image ' + n + ' loaded');
if (document.images[++n]) {
imageLoading(n);
}
};
downloadingImage.src = image.getAttribute("data-src");
}
document.addEventListener("DOMContentLoaded", function(event) {
setTimeout(function() {
imageLoading(0);
}, 0);
});
And change every src
attribute of image element to data-src
data-src is undefined
– Jack Kasbrack
Nov 18 at 21:44
Have you changed every src attribute of image element to data-src and is filled ?
– ribrow
Nov 20 at 13:18
none of them have a data-src attribute
– Jack Kasbrack
Nov 20 at 14:25
I said change them, or more specifically replace them...
– ribrow
Nov 20 at 15:30
There''s nothing to replace, it doesn't exist. Do I just add it?
– Jack Kasbrack
Nov 20 at 18:05
add a comment |
up vote
0
down vote
I am using this, works as expected:
var imageLoading = function(n) {
var image = document.images[n];
var downloadingImage = new Image();
downloadingImage.onload = function(){
image.src = this.src;
console.log('Image ' + n + ' loaded');
if (document.images[++n]) {
imageLoading(n);
}
};
downloadingImage.src = image.getAttribute("data-src");
}
document.addEventListener("DOMContentLoaded", function(event) {
setTimeout(function() {
imageLoading(0);
}, 0);
});
And change every src
attribute of image element to data-src
data-src is undefined
– Jack Kasbrack
Nov 18 at 21:44
Have you changed every src attribute of image element to data-src and is filled ?
– ribrow
Nov 20 at 13:18
none of them have a data-src attribute
– Jack Kasbrack
Nov 20 at 14:25
I said change them, or more specifically replace them...
– ribrow
Nov 20 at 15:30
There''s nothing to replace, it doesn't exist. Do I just add it?
– Jack Kasbrack
Nov 20 at 18:05
add a comment |
up vote
0
down vote
up vote
0
down vote
I am using this, works as expected:
var imageLoading = function(n) {
var image = document.images[n];
var downloadingImage = new Image();
downloadingImage.onload = function(){
image.src = this.src;
console.log('Image ' + n + ' loaded');
if (document.images[++n]) {
imageLoading(n);
}
};
downloadingImage.src = image.getAttribute("data-src");
}
document.addEventListener("DOMContentLoaded", function(event) {
setTimeout(function() {
imageLoading(0);
}, 0);
});
And change every src
attribute of image element to data-src
I am using this, works as expected:
var imageLoading = function(n) {
var image = document.images[n];
var downloadingImage = new Image();
downloadingImage.onload = function(){
image.src = this.src;
console.log('Image ' + n + ' loaded');
if (document.images[++n]) {
imageLoading(n);
}
};
downloadingImage.src = image.getAttribute("data-src");
}
document.addEventListener("DOMContentLoaded", function(event) {
setTimeout(function() {
imageLoading(0);
}, 0);
});
And change every src
attribute of image element to data-src
answered Nov 17 at 10:53
ribrow
1
1
data-src is undefined
– Jack Kasbrack
Nov 18 at 21:44
Have you changed every src attribute of image element to data-src and is filled ?
– ribrow
Nov 20 at 13:18
none of them have a data-src attribute
– Jack Kasbrack
Nov 20 at 14:25
I said change them, or more specifically replace them...
– ribrow
Nov 20 at 15:30
There''s nothing to replace, it doesn't exist. Do I just add it?
– Jack Kasbrack
Nov 20 at 18:05
add a comment |
data-src is undefined
– Jack Kasbrack
Nov 18 at 21:44
Have you changed every src attribute of image element to data-src and is filled ?
– ribrow
Nov 20 at 13:18
none of them have a data-src attribute
– Jack Kasbrack
Nov 20 at 14:25
I said change them, or more specifically replace them...
– ribrow
Nov 20 at 15:30
There''s nothing to replace, it doesn't exist. Do I just add it?
– Jack Kasbrack
Nov 20 at 18:05
data-src is undefined
– Jack Kasbrack
Nov 18 at 21:44
data-src is undefined
– Jack Kasbrack
Nov 18 at 21:44
Have you changed every src attribute of image element to data-src and is filled ?
– ribrow
Nov 20 at 13:18
Have you changed every src attribute of image element to data-src and is filled ?
– ribrow
Nov 20 at 13:18
none of them have a data-src attribute
– Jack Kasbrack
Nov 20 at 14:25
none of them have a data-src attribute
– Jack Kasbrack
Nov 20 at 14:25
I said change them, or more specifically replace them...
– ribrow
Nov 20 at 15:30
I said change them, or more specifically replace them...
– ribrow
Nov 20 at 15:30
There''s nothing to replace, it doesn't exist. Do I just add it?
– Jack Kasbrack
Nov 20 at 18:05
There''s nothing to replace, it doesn't exist. Do I just add it?
– Jack Kasbrack
Nov 20 at 18:05
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53160578%2fhow-do-i-make-a-webpage-think-its-images-are-done-loading%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You should scrape only the web page HTML and load it in a DOM parser utility. This should be done in a command line application and not in browser...
– Niloct
Nov 5 at 19:28
What is the purpose? Do you want the images take the place it should take even if it didn't yet completely load?
– A. Meshu
Nov 5 at 19:32
I want to extract the image URLs into a text file.
– Jack Kasbrack
Nov 5 at 20:20
This doesn't make much sense. Can you provide the link to the website in question?
– Unglückspilz
Nov 12 at 11:50