Last active
August 13, 2020 02:23
-
-
Save imneonizer/23d2faa12833716e22830f807b082a58 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// collect images links | |
function collect(){ | |
images = document.getElementsByClassName("serp-item") | |
images = Object.keys(images).map(key => JSON.parse(images[key].getAttribute("data-bem"))['serp-item']["img_href"]) | |
return images | |
} | |
// returs boolean value to check if page end has reached | |
function footer_hidden(){ | |
return document.getElementsByClassName('footer')[0].getAttribute('class').includes('footer_hidden_yes') | |
} | |
function scroll(){ | |
$(document).scrollTop($(document).height()); | |
} | |
// function to save and download url text file | |
function save(file_name, links){ | |
var textToSave = links.join("\n"); | |
var hiddenElement = document.createElement('a'); | |
hiddenElement.href = 'data:attachment/text,' + encodeURI(textToSave); | |
hiddenElement.target = '_blank'; | |
hiddenElement.download = file_name; | |
hiddenElement.click(); | |
} | |
var timeoutId = null; | |
var links = null; | |
function collect_images(file_name) { | |
if (!footer_hidden()){ | |
// when all the images are loaded | |
console.log("finished"); | |
links = collect(); | |
save(file_name, links); | |
} | |
// while images are loading | |
console.log("collected images: ", collect().length); | |
// scroll page down | |
scroll(); | |
// reschedule function call | |
if (footer_hidden()){ | |
//timeoutId = setTimeout(collect_images, 3000); | |
setTimeout(function() { | |
collect_images(file_name); | |
}, 3000) | |
} | |
} | |
collect_images("urls.txt") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yandex images crawler
ctrl+shift+j
and navigate to JS console tab.