feat: add image saving
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,2 +1,4 @@
|
|||||||
.venv
|
.venv
|
||||||
__pycache__
|
__pycache__
|
||||||
|
*.png
|
||||||
|
images
|
||||||
27
main.py
27
main.py
@@ -1,45 +1,54 @@
|
|||||||
import math
|
import math
|
||||||
import random
|
import random
|
||||||
|
from io import BytesIO
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
from selenium import webdriver
|
|
||||||
import selenium
|
import selenium
|
||||||
|
from PIL import Image
|
||||||
|
from selenium import webdriver
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
from selenium.webdriver.common.action_chains import ActionChains
|
from selenium.webdriver.common.action_chains import ActionChains
|
||||||
|
|
||||||
from random_pilot import RandomPilot
|
from random_pilot import RandomPilot
|
||||||
|
|
||||||
options = webdriver.ChromeOptions()
|
options = webdriver.ChromeOptions()
|
||||||
options.add_experimental_option("detach", True)
|
# options.add_experimental_option("detach", True)
|
||||||
driver = webdriver.Chrome(options)
|
driver = webdriver.Chrome(options)
|
||||||
|
|
||||||
driver.get("https://yandex.ru/maps/43/kazan/?ll=49.103814%2C55.794258&z=14")
|
driver.get("https://yandex.ru/maps/43/kazan/?ll=49.103814%2C55.794258&z=14")
|
||||||
sleep(5)
|
sleep(2)
|
||||||
|
|
||||||
html = driver.find_element(By.TAG_NAME, 'html')
|
html = driver.find_element(By.TAG_NAME, 'html')
|
||||||
|
canvas = driver.find_element(By.TAG_NAME, 'canvas')
|
||||||
action = ActionChains(driver)
|
action = ActionChains(driver)
|
||||||
|
|
||||||
# Закрытие левой панели
|
# Закрытие левой панели
|
||||||
action.click(driver.find_element(By.CLASS_NAME, 'sidebar-toggle-button'))
|
action.click(driver.find_element(By.CLASS_NAME, 'sidebar-toggle-button'))
|
||||||
action.pause(0.2)
|
|
||||||
action.move_to_element_with_offset(driver.find_element(By.XPATH, "//div[@class='rounded-controls']/div[@class='rounded-controls__child'][5]//button"), 5, 5)
|
action.move_to_element_with_offset(driver.find_element(By.XPATH, "//div[@class='rounded-controls']/div[@class='rounded-controls__child'][5]//button"), 5, 5)
|
||||||
action.pause(0.2)
|
|
||||||
action.perform()
|
action.perform()
|
||||||
|
|
||||||
# Режим спутника
|
# Режим спутника
|
||||||
action.click(driver.find_element(By.CLASS_NAME, '_key_satellite'))
|
action.click(driver.find_element(By.CLASS_NAME, '_key_satellite'))
|
||||||
action.pause(0.2)
|
|
||||||
action.perform()
|
action.perform()
|
||||||
|
|
||||||
|
|
||||||
randomPilot = RandomPilot(100)
|
randomPilot = RandomPilot(100)
|
||||||
|
|
||||||
while True:
|
for i in range(100):
|
||||||
# Сдвиг камеры
|
# Сдвиг камеры
|
||||||
action = ActionChains(driver)
|
action = ActionChains(driver)
|
||||||
action.move_to_element_with_offset(html, 200, 200)
|
action.move_to_element_with_offset(html, 200, 200)
|
||||||
action.click_and_hold()
|
action.click_and_hold()
|
||||||
action.move_by_offset(*randomPilot.step())
|
dx, dy = randomPilot.step()
|
||||||
|
action.move_by_offset(-dx, dy)
|
||||||
action.release()
|
action.release()
|
||||||
action.perform()
|
action.perform()
|
||||||
sleep(0.5)
|
|
||||||
|
# Загрузка скриншота
|
||||||
|
png = driver.get_screenshot_as_png()
|
||||||
|
im = Image.open(BytesIO(png))
|
||||||
|
im = im.crop([0, 80, im.width-80, im.height-60])
|
||||||
|
im.save(f"./images/{i}.png")
|
||||||
|
sleep(0.25)
|
||||||
|
|
||||||
|
print("last position: ", driver.current_url)
|
||||||
|
|||||||
Reference in New Issue
Block a user