Created
April 15, 2017 06:08
-
-
Save xhiroga/8b260cd29d8542d562113156e0ef95f7 to your computer and use it in GitHub Desktop.
(第75回)Python mini Hack-a-thonの成果物! #pyhack
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
#!python | |
#-*-coding:utf-8-*- | |
# before run this source, | |
# 1. pip install selenium | |
# 2. npm install -g phantomjs | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys as keys | |
import time | |
import os | |
def main(): | |
driver = webdriver.PhantomJS() | |
driver.get("https://2016.spaceappschallenge.org/challenges/earth/sea-ice-app/projects") | |
str = driver.page_source | |
f = open('before.html', 'w') | |
f.write(str) | |
f.close() | |
# この時点で取得したソースには、そもそもボタンがない? -> ロードを待つ必要があった! | |
print ("wait 5 second") | |
time.sleep(5) | |
if os.path.isfile("before.png"): os.remove("before.png") | |
driver.get_screenshot_as_file('before.png') # 5秒待ってスクショ | |
button = driver.find_element_by_css_selector("button.ui---chunkyButton---CHoDI") | |
print ("get button") | |
print (type(button)) | |
button.send_keys(keys.ENTER) # なんて直感的にボタンが押せるんだろうか。感動した。 | |
print ("click and wait 5 second") | |
time.sleep(5) | |
if os.path.isfile("after.png"): os.remove("after.png") | |
driver.get_screenshot_as_file('after.png') | |
driver.close() | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment