【爬虫】从地理空间数据云上批量下载遥感影像

基于python的selenuim库,利用遥感影像数据标识从地理空间数据云上下载对应的遥感影像

针对Landsat系列数据

爬取网页的时候需要time.sleep(),否则可能网页还没加载出来,命令已经进行下去了,这样的话便无法定位到你想要的元素,导致爬取失败

输入

将要下载的数据标识排在第一列
在这里插入图片描述

有空再写一个USGS的下载。

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

def download(data_list):
	for i in data_list:
		if i[:3]=='LE7':
			A=driver.find_element_by_xpath(dict1[i[:3]+'_on']).click()
			time.sleep(3)
			B=driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[1]/div[1]/div[2]/div[2]/div[2]/div[2]/div[1]/table/tr[1]/td[2]/div/input')
			B.send_keys(i)
			B.send_keys(Keys.ENTER)
			time.sleep(3)
			q=driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[1]/div[1]/div[2]/div[2]/div[2]/div[2]/div[1]/table/tr[3]/td').text
			if str(q)=="没有记录!":
				D=driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[1]/div[1]/div[2]/div[1]/div[1]/nav/ol/li[2]').click()
				time.sleep(3)
				A=driver.find_element_by_xpath(dict1[i[:3]+'_off']).click()
				time.sleep(3)
				B=driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[1]/div[1]/div[2]/div[2]/div[2]/div[2]/div[1]/table/tr[1]/td[2]/div/input')
				B.send_keys(i)
				B.send_keys(Keys.ENTER)
				time.sleep(3)
				C=driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[1]/div[1]/div[2]/div[2]/div[2]/div[2]/div[1]/table/tr[3]/td[11]/div/div/p[2]')
				C.click()
				time.sleep(3)
				D=driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[1]/div[1]/div[2]/div[1]/div[1]/nav/ol/li[2]').click()
				time.sleep(3)
			else:
				C=driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[1]/div[1]/div[2]/div[2]/div[2]/div[2]/div[1]/table/tr[3]/td[11]/div/div/p[2]')
				C.click()
				time.sleep(3)
				D=driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[1]/div[1]/div[2]/div[1]/div[1]/nav/ol/li[2]').click()
				time.sleep(3)
		else:
			A=driver.find_element_by_xpath(dict1[i[:3]]).click()
			time.sleep(3)
			B=driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[1]/div[1]/div[2]/div[2]/div[2]/div[2]/div[1]/table/tr[1]/td[2]/div/input')
			B.send_keys(i)
			B.send_keys(Keys.ENTER)
			time.sleep(3)
			C=driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[1]/div[1]/div[2]/div[2]/div[2]/div[2]/div[1]/table/tr[3]/td[11]/div/div/p[2]/img')
			C.click()
			time.sleep(3)
			D=driver.find_element_by_xpath('/html/body/div[1]/div[3]/div[1]/div[1]/div[2]/div[1]/div[1]/nav/ol/li[2]').click()
			time.sleep(3)

def extract_water(excel):
	#从excel中提取遥感影像的数据标识信息
	import xlrd
	workbook=xlrd.open_workbook(excel)
	sheet1=workbook.sheet_by_name("29_31")
	data_list=[]
	for i in range(1,sheet1.nrows):
		idenfication=str(sheet1.cell(i,0).value)
		data_list.append(idenfication)
	return data_list

r=extract_water(r'C:\Users\23932\Desktop\毕设\29_31.xlsx')
print(r)

#创建字段来映射卫星和网址
dict1={}
dict1['LT4']='/html/body/div[1]/div[3]/div[1]/div[1]/div[2]/div[2]/div[2]/div/div[2]/div[4]'#TM传感器
dict1['LT5']='/html/body/div[1]/div[3]/div[1]/div[1]/div[2]/div[2]/div[2]/div/div[2]/div[4]'#TM传感器
dict1['LC8']='/html/body/div[1]/div[3]/div[1]/div[1]/div[2]/div[2]/div[2]/div/div[2]/div[1]'#OLI传感器
dict1['LE7_off']='/html/body/div[1]/div[3]/div[1]/div[1]/div[2]/div[2]/div[2]/div/div[2]/div[2]'#ETM传感器
dict1['LE7_on']='/html/body/div[1]/div[3]/div[1]/div[1]/div[2]/div[2]/div[2]/div/div[2]/div[3]'#ETM传感器
#

#登录
driver = webdriver.Chrome(executable_path = r'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe')
driver.get('http://www.gscloud.cn/accounts/login_user')
email = driver.find_element_by_xpath('//input[@id="email"]')
email.send_keys('xxxx') #账号
password = driver.find_element_by_xpath('//input[@id="password"]')
password.send_keys('xxxxx') #密码
captcha = driver.find_element_by_xpath('//input[@id="id_captcha_1"]')
captcha_sj = input('请输入验证码:').strip()
captcha.send_keys(captcha_sj)
dr_buttoon=driver.find_element_by_xpath('//input[@id="btn-login"]').click() #输入验证码后点击登入按钮
time.sleep(10)
#进入‘公开数据’页面
B=driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/ul/li/a').click()
time.sleep(5)
BC=driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/ul/li/div/ul/li[1]/a').click()
time.sleep(10)

download(r)

如果你也厌倦了在gscloud上一页一页翻找需要的遥感影像,不妨试试用python在数据云上爬取符合条件的遥感影像信息,这可以帮你节省大量时间:
根据水文资料(水位/流量)爬取地理空间数据云遥感影像信息
根据月份从地理空间数据云上爬取遥感影像信息

需要提取水体吗?可以看看这个(使用IDL对Landsat系列进行批量水体提取

  • 6
    点赞
  • 43
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值