imajnet automatic image capturing python script

Veröffentlicht am: 26 Juli 2023
auf dem Kanal: R FILMS
55
0

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
import time
import os
import pyautogui

Path to Firefox binary
binary_path = r'C:\Program Files\Mozilla Firefox\firefox.exe'

options = Options()
options.binary_location = binary_path

create a new Firefox session
driver = webdriver.Firefox(options=options, service=Service('D:\\Programs\\Geckodriver\\geckodriver.exe'))
driver.implicitly_wait(5)
driver.maximize_window()

Navigate to the application home page
driver.get("https://web.imajnet.net/#loc=45.43901...")

Fill in the username
username_field = driver.find_element(By.ID, 'username') # replace with the actual id
username_field.send_keys("user")# remplacer avec username

Fill in the password
password_field = driver.find_element(By.ID, 'password') # replace with the actual id
password_field.send_keys("mdp")# remplacer avec mdp

Wait for a bit before clicking the button
time.sleep(2)

Click the login button
login_button = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, 'imajnetLoginButton')))

Click the login button using JavaScript
driver.execute_script("arguments[0].click();", login_button)

Wait for the login to complete
time.sleep(2)

Initialize ActionChains
actions = ActionChains(driver)


#download first image
download_button = driver.find_element(By.ID, "imajnetSaveImage")
download_button.click()
time.sleep(0.3)
Switch to the new tab (assuming it is the second tab)
driver.switch_to.window(driver.window_handles[1])
time.sleep(1)
img = driver.find_element(By.TAG_NAME, "img")
Take a screenshot of the image and save it
img.screenshot(os.path.join("D:/NCH/20230720 GARE UZERCHE/PHOTOS/V2.new", f"image_0.png"))
Close the current tab
driver.close()
Switch back to the original tab
driver.switch_to.window(driver.window_handles[0])
time.sleep(0.5)


Repeat the process X times to download X images
for i in range(1, 64):
Scroll up X times to advance 3*X meters
for _ in range(3):
Select the div with id "zMapCanvas"
scroll_area = driver.find_element(By.ID, "zMapCanvas")
Wait for a bit before clicking the scroll area
time.sleep(0.5)

Click on the scroll area to set the focus
actions.click(scroll_area).perform()
actions.send_keys(Keys.ARROW_UP).perform()
time.sleep(0.5)



Download the image
download_button = driver.find_element(By.ID, "imajnetSaveImage")
download_button.click()

Wait for the new tab to open
time.sleep(1)

Switch to the new tab (assuming it is the second tab)
driver.switch_to.window(driver.window_handles[1])

time.sleep(1)

img = driver.find_element(By.TAG_NAME, "img")

Take a screenshot of the image and save it
img.screenshot(os.path.join("D:/NCH/20230720 GARE UZERCHE/PHOTOS/V1.new", f"image_{i}.png"))

Close the current tab
driver.close()

Switch back to the original tab
driver.switch_to.window(driver.window_handles[0])
time.sleep(0.5)


Auf dieser Seite können Sie das Online-Video imajnet automatic image capturing python script mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer R FILMS 26 Juli 2023 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 55 Mal angesehen und es wurde von 0 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!