Created
January 8, 2015 14:21
-
-
Save mrwooten/9bda94f3490e5c01ab1d to your computer and use it in GitHub Desktop.
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
import selenium | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.support.ui import Select | |
##path = "C://Users//mwooten3//Desktop//" # windows path (and download directory) | |
## to use on linux: (don't forget to comment/uncomment last line) | |
from pyvirtualdisplay import Display | |
display = Display(visible = 0, size = (800, 600)) | |
display.start() | |
path = '/mnt/data-store/Maggie/' | |
## example input variables (will be determined by AOI) | |
# if using scenes as input | |
path_from = '030' | |
path_to = '031' | |
row_from = '020' | |
row_to = '021' | |
# if using lat/long coords as input | |
UL_lat = '43' | |
UL_lon = '-112' | |
LR_lat = '41' | |
LR_lon = '-110' | |
# to-from date (example) | |
month1 = '05' | |
day1 = '27' | |
year1 = '2012' | |
date_from = month1 + '/' + day1 + '/' + year1 | |
month2 = '08' | |
day2 = '01' | |
year2 = '2014' | |
date_to = month2 + '/' + day2 + '/' + year2 | |
cloud = 'All' # change this variable to discriminate cloud coverage (i.e. 'Less than 10%') | |
# to automatically save file- not working | |
profile = webdriver.FirefoxProfile() | |
profile.set_preference('browser.download.manager.showWhenStarting', False) | |
profile.set_preference('browser.download.folderList', 2) | |
profile.set_preference("browser.download.dir", path) | |
profile.set_preference("browser.download.downloadDir", path) | |
profile.set_preference("browser.download.defaultFolder", path) | |
profile.set_preference('browser.helperApps.neverAsk.saveToDisk',"text/csv") | |
profile.set_preference("browser.helperApps.neverAsk.openFile", "CONTENT-TYPE") | |
# using examples from http://selenium-python.readthedocs.org/en/latest/getting-started.html | |
#driver = webdriver.PhantomJS(executable_path = 'C:\\Users\\mwooten3\\Downloads\\phantomjs-1.9.8-windows') # create Firefox WebDriver instance | |
driver = webdriver.Firefox(profile) | |
driver.get("http://landsat.usgs.gov/consumer.php") # navigate to landsat bulk ordering page, load, then return control to script | |
#assert "Python" in driver.title # dunno why you have to do this | |
#### if using scenes as input: | |
### find path/row elements by searching via name: | |
##begin_path = driver.find_element_by_name('begin_path') | |
##end_path = driver.find_element_by_name('end_path') | |
##begin_row = driver.find_element_by_name('begin_row') | |
##end_row = driver.find_element_by_name('end_row') | |
## | |
### send path/row to site | |
##begin_path.send_keys(path_from) # can also use just begin_path and use arrows to fill out rest | |
##end_path.send_keys(path_to) | |
##begin_row.send_keys(row_from) | |
##end_row.send_keys(row_to) | |
## if using lat/long as input: | |
#find lat/long elements | |
lat1 = driver.find_element_by_name('lat1') | |
lon1 = driver.find_element_by_name('long1') | |
lat2 = driver.find_element_by_name('lat2') | |
lon2 = driver.find_element_by_name('long2') | |
# click choose by lat/long and send coords to form: | |
driver.find_element_by_id('lat_long_head').click() | |
lat1.send_keys(UL_lat) | |
lon1.send_keys(UL_lon) | |
lat2.send_keys(LR_lat) | |
lon2.send_keys(LR_lon) | |
# enter additional criteria | |
# select sensor (4-8 combined) | |
sensor = driver.find_element_by_name('sensor') | |
chooseSensor = Select(sensor) | |
chooseSensor.select_by_value('LANDSAT_COMBINED') | |
# enter date range and cloud coverage | |
start_date = driver.find_element_by_name('start_date') | |
end_date = driver.find_element_by_name('end_date') | |
start_date.send_keys(date_from) | |
end_date.send_keys(date_to) | |
cc = driver.find_element_by_name('cloud_cover') | |
chooseCC = Select(cc) | |
chooseCC.select_by_value(cloud) | |
### choose to search months only (or if you don't want to search months only, comment out) | |
##monthsOnly = driver.find_element_by_name('months_only') | |
##monthsOnly.click() | |
###look at all options (different from dir(class)?) | |
##all_options = monthsOnly.find_elements_by_tag_name("option") | |
##for option in all_options: | |
## print("Value is: %s" % option.get_attribute("value")) | |
## option.click() | |
# submit form to espa | |
submit = driver.find_element_by_name('submit').click() | |
### doesn't work: | |
##from selenium.webdriver.common.alert import Alert(submit) | |
### save file | |
##alert = driver.switch_to_alert() | |
##driver.implicitly_wait(10) | |
##alert.send_keys(Keys.ARROW_DOWN) | |
## | |
##print dir(alert) | |
display.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment