Home > other >  Download hycom data in Python
Download hycom data in Python

Time:05-15

In this paper, using the python selenium to automation of web pages, and download in the form of circulation hycom website NetcdfSubset data in

(1) after choose to hycom data set, choose NetcdfSubset download interface is a link to the page, such as below:



This page can only choose scattered data download, if you want to download a year or years of data, always can't a a dot,
(2) so I choose to use python file download more selenium, and about the specification of the selenium and the corresponding browser driver download on the https://blog.csdn.net/shiaohan/article/details/108834770 post made it very clear, after installed the corresponding library, as the chart, you can begin to write:


(3) fill in the corresponding address, in case one thousand added behind the driver. Implicitly_wait (time) for a period of waiting for
 driver=webdriver. Chrome (' D: \ \ chromedriver \ \ chromedriver exe ') # Optional argument, if not specified will search path. 
Driver. The get (' http://ncss.hycom.org/thredds/ncss/grid/GLBv0.08/expt_53.X/data/2008/dataset.html ')
Driver. Implicitly_wait (20)

(4) then there is a web page other box selection, basic it is not difficult, when choosing the output format here appeared a drop-down selection box, is I use the select function, this function is explained in this https://www.cnblogs.com/w770762632/p/8745261.html has very good,
 # click ele 
Driver. Find_element_by_xpath ('//* [@ id="form"]/table/tbody/tr [1] [1]/td/blockquote/input [2] '). Click ()
# click S, T, U, V
Driver. Find_element_by_xpath ('//* [@ id="form"]/table/tbody/tr [1] [1]/td/blockquote/input [6] '). Click ()
Driver. Find_element_by_xpath ('//* [@ id="form"]/table/tbody/tr [1] [1]/td/blockquote/input [7] '). Click ()
Driver. Find_element_by_xpath ('//* [@ id="form"]/table/tbody/tr [1] [1]/td/blockquote/input [8] '). Click ()
Driver. Find_element_by_xpath ('//* [@ id="form"]/table/tbody/tr [1] [1]/td/blockquote/input [9] '). Click ()
Driver. Implicitly_wait (5)
# click Disable horizontal subsetting
Driver. Find_element_by_xpath ('//* [@ id="disableLLSubset"] '). Click ()

# input lat, lon
Driver. Find_element_by_xpath ('//* [@ id="latlonSubset"]/div [1]/input [1] '). The clear ()
Driver. Find_element_by_xpath ('//* [@ id="latlonSubset"]/div [1]/input [1] '). The send_keys (' 18 ')
Driver. Find_element_by_xpath ('//* [@ id="latlonSubset"]/div [2]/input [1] '). The clear ()
Driver. Find_element_by_xpath ('//* [@ id="latlonSubset"]/div [2]/input [1] '). The send_keys (' 105 ')
Driver. Find_element_by_xpath ('//* [@ id="latlonSubset"]/div [2]/input [3] '). The clear ()
Driver. Find_element_by_xpath ('//* [@ id="latlonSubset"]/div [2]/input [3] '). The send_keys (' 115 ')
Driver. Find_element_by_xpath ('//* [@ id="latlonSubset"]/div [3]/input [1] '). The clear ()
Driver. Find_element_by_xpath ('//* [@ id="latlonSubset"]/div [3]/input [1] '). The send_keys (' 9 ')
Driver. Implicitly_wait (1)

# click vertical stride
Driver. Find_element_by_xpath ('//* [@ id="inputVerticalStride"]/span '). Click ()
Driver. Implicitly_wait (1)

# click to add lat/lon variables
Driver. Find_element_by_xpath ('//* [@ id="form"]/table/tbody/tr [1] [2]/td/div [12]/input '). Click ()

# choose the output format
S=driver. Find_element_by_name (' accept ')
Select (s). Select_by_value (' netcdf ')

(5) after get the basic options, then there is the use cycle write time for batch download, considering the factors such as network fluctuation, I here is the monthly download,
 # click single time, and the input data_time 
N=0
For I in range (1, 31) :
N=n + 1
N=STR (I). Zfill (2)
='2008-01 -' keys + N + 'T12:00:00 Z'
Print (keys)
Driver. Find_element_by_xpath ('//* [@ id="singleTimeSubset"]/input '). The clear ()
Driver. Find_element_by_xpath ('//* [@ id="singleTimeSubset"]/input '). The send_keys (keys)
Driver. Implicitly_wait (10)

# click to submit
Driver. Find_element_by_xpath ('//* [@ id="form"]/table/tbody/tr [3]/td/input [1] '). Click ()
Time. Sleep (120)

(6) END

  • Related