Handle errors, remove menu bar, centre graphs

This commit is contained in:
Tanner Collin 2023-04-18 21:18:55 +00:00
parent a7ca48dacf
commit c693d30394

View File

@ -4,16 +4,20 @@ from selenium import webdriver
from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.service import Service
from selenium.common.exceptions import NoSuchElementException
from webdriver_manager.chrome import ChromeDriverManager from webdriver_manager.chrome import ChromeDriverManager
ser = Service('/usr/lib/chromium-browser/chromedriver') ser = Service('/usr/lib/chromium-browser/chromedriver')
chrome_options = Options() chrome_options = Options()
chrome_options.add_argument('--headless') chrome_options.add_argument('--headless')
chrome_options.add_argument('start-maximized')
chrome_options.add_argument('--no-sandbox') chrome_options.add_argument('--no-sandbox')
driver = webdriver.Chrome(service=ser, options=chrome_options) driver = webdriver.Chrome(service=ser, options=chrome_options)
driver.get('https://sensors.dns.t0.vc') driver.get('https://sensors.dns.t0.vc')
time.sleep(3) time.sleep(3)
driver.execute_script("return document.getElementsByClassName('menu')[0].remove();")
graphs = [ graphs = [
'Solar_Power', 'Solar_Power',
'Living_Room_Air', 'Living_Room_Air',
@ -29,9 +33,16 @@ graphs = [
for graph in graphs: for graph in graphs:
print('Capturing', graph, 'graph...') print('Capturing', graph, 'graph...')
element = driver.find_element(By.ID, graph)
with open('data/{}.png'.format(graph), 'wb') as f: try:
element = driver.find_element(By.ID, graph)
except NoSuchElementException:
print('Graph not found, skipping.')
continue
driver.execute_script('arguments[0].scrollIntoView({block: "center"});', element)
with open('/home/tanner/sensors/export/data/{}.png'.format(graph), 'wb') as f:
f.write(element.screenshot_as_png) f.write(element.screenshot_as_png)
driver.close() driver.close()