采用Selenium+Chromedriver方式下载,具体安装Selenium+Chromedriver请看
https://zhuanlan.zhihu.com/p/588679601
(1)Python没有自带selenium库,需要自行下载,只需要用简单的命令即可实现:
pip install selenium
(2)安装Chrome浏览器
(3)接着去下载对应版本的Chromedriver。通常从以下网址下载:
https://npm.taobao.org/mirrors/
(4)下载程序:from selenium import webdriver import time from selenium.webdriver.common.keys import Keys from selenium.webdriver.support import expected_conditions from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.common.by import By import os driver = webdriver.Chrome(executable_path=r'C:\Users\Hx\AppData\Local\Programs\Python\Python310\chromedriver.exe') driver.get('http://www.gscloud.cn/accounts/login_user') urlpage = driver.current_url dem = r'https://www.gscloud.cn/sources/accessdata/aeab8000652a45b38afbb7ff023ddabb?pid=302' while urlpage!=dem: urlpage = driver.current_url time.sleep(1) # 开始下载 # #一共是7页 page_num = 382 page = 1 while page <= page_num: print('当前下载第{}页'.format(page)) for tr_num in range(1,10): # 每页10个 # d_everypage = '//*[@id="datasource"]/div/table/tr[dlv-row dlv-row-'+str(tr_num)+']/td[8]/div/div/p[2]/img' d_everypage = '//*[@id="datasource"]/div/table/tr['+str(2+tr_num)+']/td[9]/div/div/p[2]/img' WebDriverWait(driver, 20).until(expected_conditions.visibility_of_element_located((By.XPATH, d_everypage))) # 翻页后重新定位,否则报错ElementClickInterceptedException: #element = driver.find_element_by_xpath(d_everypage) element = driver.find_element(By.XPATH, d_everypage) webdriver.ActionChains(driver).move_to_element(element).click(element).perform() time.sleep(5) #下载间隔 page += 1 next = driver.find_element(By.XPATH, '//*[@id="pager"]/div/table/tr/td[10]/a/span/span/span').click() # 下一页 time.sleep(3)(5)运行后,会打开Chrome浏览器
请进行登录后。
(6)设置Chrome下载目录
(7)点击”数据资源“-》“公开数据”-》“DEM 数字高程模型”-》GDEMV3 30M 分辨率数字高程数据
(8)进入“GDEMV3 30M 分辨率数字高程数据”页面后,程序将从等待状态开始进入自动下载。