Created
October 15, 2017 23:47
-
-
Save fuwac/f166731c936f177cd1691425514d1399 to your computer and use it in GitHub Desktop.
pythonでWEBの画像キャプチャするやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: UTF-8 | |
from selenium import webdriver | |
from selenium.webdriver.common.by import By | |
from selenium.webdriver.support.ui import WebDriverWait | |
from selenium.webdriver.support import expected_conditions as EC | |
import datetime | |
url = r"http://hogefuga:5601/app/kibana#/visualize/edit/foobar&embed=true" | |
out_path = r"Z:\share\graph" | |
# 現在の日付を取得 | |
now_date = datetime.datetime.now() | |
now_date_str = now_date.strftime("%y%m%d") | |
out_path = out_path + r"/graph_" + now_date_str + r".png"; | |
# chrome起動&URLアクセス | |
ch = webdriver.Chrome(executable_path=r"C:\Python34\Lib\selenium\chromedriver.exe") | |
ch.set_window_size(1000, 500) | |
ch.get(url) | |
# 特定のclassが出るまでウェイト! | |
try: | |
element = WebDriverWait(ch, 30).until( | |
EC.presence_of_all_elements_located((By.CLASS_NAME, "chart")) | |
) | |
except: | |
print("たぶんタイムアウトかなにかだよ") | |
# 小細工 | |
ch.execute_script("$('.filter-bar').hide();") # いらん要素を消す(jquery) | |
# SS保存 | |
ch.save_screenshot(out_path) | |
ch.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment