I want to display the screen of an external service that requires login together with the signage that displays the image file as a slide show. It's a little difficult to understand, but it looks like the following.
It would be helpful if you could read the file name, save destination, login information, etc. as appropriate.
import os
import sys
import time
import datetime
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import chromedriver_binary
# File Name
now = datetime.datetime.now()
filename = "image/screen_" + now.strftime('%Y%m%d_%H%M%S') + ".png "
FILENAME = os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)
# set driver and url
options = Options()
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)
url = 'https://xxxx/xxxx/'
driver.get(url)
# ID/Enter PASS (Adjustment required for each site)
id = driver.find_element_by_name("xxxx-xxxx")
id.send_keys("xxxx")
password = driver.find_element_by_name("xxxx-xxxx")
password.send_keys("xxxx")
time.sleep(1)
#Click the login button (this requires adjustment for each site)
login_button = driver.find_element_by_name("xxxx")
login_button.click()
# get width and height of the page
w = driver.execute_script("return document.body.scrollWidth;")
h = driver.execute_script("return document.body.scrollHeight;")
# set window size
driver.set_window_size(1920,1080)
time.sleep(1)
# Get Screen Shot
print ("Get Screen Shot")
driver.save_screenshot(FILENAME)
# Close Web Browser
driver.quit()
For the time being, I was able to do what I wanted to do with the above flow. After that, I'm currently doing it in a local environment, so I want to move this to a server environment. Now that I understand the general flow, I feel that I can manage it by investigating the rest.
In my environment, I assigned the signage publishing folder to the network drive, but when I started python directly with the task scheduler, the access to the network drive did not work, so I created a batch file separately. So I assigned a network drive in batch and then started python and it worked. So, at present, the mechanism is such that the batch file is executed regularly.
Recommended Posts