Python - Access React Props using Selenium Python - Access React Props using Selenium selenium selenium

Python - Access React Props using Selenium


You don't need to know any framework to automate any page. You need to just access the DOM and you can do that with selenium and python. But sometimes some simple Vanilla JavaScript helps.

To get those links you can try and paste this in console:

images_links =[]; images = document.querySelectorAll("img"); for (image of images){images_links.push(image.src)} console.log(images_links)

Also the selenium with python and the above JS snippet is:

import seleniumfrom selenium import webdriverfrom time import sleepdriver = webdriver.Chrome()driver.get("https://imgur.com/a/JNzjB")for i in range(0,7): # here you will need to tune to see exactly how many scrolls you need  driver.execute_script('window.scrollBy(0, 2000)')sleep(2)list_of_images_links=driver.execute_script('images_links =[]; images = document.querySelectorAll("img"); for (image of images){images_links.push(image.src)} return images_links;')list_of_images_links

enter image description here

Update:

you don't need selenium just paste this in an Opera console (see that you enable multiple Downloads) and voila:

document.body.style.zoom=0.1; images=document.querySelectorAll("img"); for (i of images) { var a = document.createElement('a'); a.href = i.src; console.log(i); a.download = i.src; document.body.appendChild(a); a.click(); document.body.removeChild(a); }

same thing beautified for reading:

document.body.style.zoom=0.1;images = document.querySelectorAll("img");for (i of images) {    var a = document.createElement('a');    a.href = i.src;    console.log(i);    a.download = i.src;    document.body.appendChild(a);    a.click();    document.body.removeChild(a);}

Update 2 Opera webdriver

import osfrom time import sleepfrom selenium import webdriverfrom selenium.webdriver.common import desired_capabilitiesfrom selenium.webdriver.opera import options_operaDriverLoc = os.path.abspath('c:\\Python27\\Scripts\\operadriver.exe')  # Replace this path with the actual path on your machine._operaExeLoc = os.path.abspath('c:\\Program Files\\Opera\\51.0.2830.34\\opera.exe')   # Replace this path with the actual path on your machine._remoteExecutor = 'http://127.0.0.1:9515'_operaCaps = desired_capabilities.DesiredCapabilities.OPERA.copy()_operaOpts = options.ChromeOptions()_operaOpts._binary_location = _operaExeLoc# Use the below argument if you want the Opera browser to be in the maximized state when launching.# The full list of supported arguments can be found on http://peter.sh/experiments/chromium-command-line-switches/_operaOpts.add_argument('--start-maximized')driver = webdriver.Chrome(executable_path = _operaDriverLoc, chrome_options = _operaOpts, desired_capabilities = _operaCaps)driver.get("https://imgur.com/a/JNzjB")for i in range(0,7): # here you will need to tune to see exactly how many scrolls you need  driver.execute_script('window.scrollBy(0, 2000)')sleep(4)driver.execute_script("document.body.style.zoom=0.1")list_of_images_links=driver.execute_script('images_links =[]; images = document.querySelectorAll("img"); for (image of images){images_links.push(image.src)} return images_links;')list_of_images_linksdriver.execute_script('document.body.style.zoom=0.1; images=document.querySelectorAll("img"); for (i of images) { var a = document.createElement("a"); a.href = i.src; console.log(i); a.download = i.src; document.body.appendChild(a); a.click(); document.body.removeChild(a); }')