最近在学习GPS数据软件处理,经常需要下载数据练习,反复去网站上很麻烦,于是就写了一个小小的爬虫,用的是韩国的服务器,使用了python中的ftplib库实现的

今天稍微改了一下代码,可以选择卫星系统,支持批量下载,可以选择年份年积日

忘了添加n文件下载功能了,今天补上

#encode=utf8
'''
Created on 2016年10月18日 @author: WangHui
'''
from ftplib import FTP
import os
import traceback class DownLoadGPS(object):
__URLon='210.219.33.196'
@staticmethod
#形参均使用字符串表示
def ListOName(form,year,daily,gnss='gps'):
ftp=FTP()
ftp.connect(DownLoadGPS.__URLon,timeout=1000000)
ftp.login()
ftp.cwd('/'+gnss+'/data/daily/'+year+'/'+daily+'/'+year[-2:]+'o/')
return ftp @staticmethod
def ListNName(form,year,daily,gnss='gps'):
ftp=FTP()
ftp.connect(DownLoadGPS.__URLon)
ftp.login()
ftp.cwd('/'+gnss+'/data/daily/'+year+'/'+daily+'/'+year[-2:]+'n/')
return ftp
@staticmethod
#下载文件
#不考虑是什么类型的数据
#只需要文件名和路径和ftp参数
def DownLoadFile(ftp,path='D:\\'):
#加载第一页的数据
DownLoadGPS.LoadPage(ftp, 1)
while True:
fileIndex=input('输入 索引(1,2,3,4,5) 开始下载,输入 n+页数(n1) 换页(按q退出) :')
if fileIndex=='q' or fileIndex=='Q':
break
if fileIndex[0]=='n' or fileIndex[0]=='N':
DownLoadGPS.LoadPage(ftp, int(fileIndex[1:]))
else:
ls=fileIndex.split(',')
for i in range(len(ls)):
try:
print('开始下载'+ls[i])
f=open(os.path.join(path,ftp.nlst()[int(i)-1]),'wb')
#A RETR request asks the server to send the contents of a file over the data connection already established by the client.
#The RETR parameter is an encoded pathname of the file.
#The file is either a binary file or a text file, depending on the most recent TYPE request.
ftp.retrbinary('RETR '+ftp.nlst()[int(i)-1],f.write)
except:
print('软件异常,不过不妨事')
@staticmethod
#加载第index页的数据
def LoadPage(ftp,index,perpage=20):
if len(ftp.nlst())==0:
print('暂时没有这天数据,q退出')
return
pagecount=len(ftp.nlst())//perpage+len(ftp.nlst())%perpage
start=(index-1)*perpage
if start>=len(ftp.nlst()):
start=len(ftp.nlst())-1
end=index*perpage
if end>len(ftp.nlst()):
end=len(ftp.nlst())
print('共%d页%d项,当前正在加载第%d页' %(pagecount,len(ftp.nlst()),index))
for i in range(start,end):
print(str(i)+' : '+ftp.nlst()[i])
print('共%d页%d项,当前是第%d页' %(pagecount,len(ftp.nlst()),index)) if __name__=='__main__':
gnss=input('输入卫星系统类型(gps,gnss):').lower()
if gnss!='gps' and gnss!='gnss':
print('请输入正确的卫星系统,系统退出')
exit()
while True:
oorn=input('o文件还是n文件(o/n):')
try:
year=input('输入年份:')
data=input('输入年积日:')
if oorn=='o':
ftp=DownLoadGPS.ListOName(gnss, year, data,gnss)
DownLoadGPS.DownLoadFile(ftp)
elif oorn=='n':
ftp=DownLoadGPS.ListNName(gnss, year, data,gnss)
DownLoadGPS.DownLoadFile(ftp)
except:
traceback.print_exc()
print('格式输入错误')
continue
isnext=input('是否继续 y/n:')
if isnext=='y' or isnext=='Y':
continue
else:
break

这是运行效果图,目前只支持gps和gnss的下载观测数据和卫星星历。

python下载IGS观测数据的更多相关文章

  1. Python下载网页的几种方法

    get和post方式总结 get方式:以URL字串本身传递数据参数,在服务器端可以从'QUERY_STRING'这个变量中直接读取,效率较高,但缺乏安全性,也无法来处理复杂的数据(只能是字符串,比如在 ...

  2. 【python 下载】-各种版本都有!

    python 是一种全功能的语言,2.7很稳定,成熟的版本,且有很多开源的模块. 小编个人觉得python有一个很大的优点,就是语法简练,甚至可以说简单.比起pascal或者 C什么的,简单的难以置信 ...

  3. Python下载Yahoo!Finance数据

    Python下载Yahoo!Finance数据的三种工具: (1)yahoo-finance package. (2)ystockquote. (3)pandas.

  4. [转] 三种Python下载url并保存文件的代码

    原文 三种Python下载url并保存文件的代码 利用程序自己编写下载文件挺有意思的. Python中最流行的方法就是通过Http利用urllib或者urllib2模块. 当然你也可以利用ftplib ...

  5. 用python下载辞典

    用python下载词源词典Etymoline Online Etymology Dictionary是最好的 English 词源词典,现在来说没有之一.但是,一直在PC上查单词有时不是很方便,遂就想 ...

  6. 如何用python下载一张图片

    如何用python下载一张图片 这里要用到的主要工具是requests这个工具,需要先安装这个库才能使用,该库衍生自urllib这个库,但是要比它更好用.多数人在做爬虫的时候选择它,是个不错的选择. ...

  7. python下载安装BeautifulSoup库

    python下载安装BeautifulSoup库 1.下载https://www.crummy.com/software/BeautifulSoup/bs4/download/4.5/ 2.解压到解压 ...

  8. python下载安装requests库

    一.python下载安装requests库 1.到git下载源码zip源码https://github.com/requests/requests 2.解压到python目录下: 3.“win+R”进 ...

  9. python下载夏目友人帳

    python下载夏目友人帐 一般情况下我们使用爬虫更多的应该是爬数据或者图片吧,今天在这里和大家分享一下关于使用爬虫技术来进行视频下载的方法,不仅可以方便的下载一些体积小的视频,针对大容量的视频下载同 ...

随机推荐

  1. Python处理XML

    在Python(以及其他编程语言)内有两种常见的方法处理XML:SAX(Simple API for XML)和DOM(Document Object Model,文档对象模型).SAX语法分析器读取 ...

  2. [译]36 Days of Web Testing(二)

    Day 7: Http 和 Https Why? 当在网络上传输一些私人,敏感信息时,应该采用加密的手段来保证这些信息在传输的过程中不被侦测到.Https协议正是这种实现机制. Https是一种广泛使 ...

  3. python学习随笔

    1 高阶函数的使用: import math def add(x, y, f): return f(x) + f(y) sq = math.sqrt print add(25, 9,sq) 2. ma ...

  4. 网页错误404 or 500

    HTTP 错误 400 400 请求出错 由于语法格式有误,服务器无法理解此请求.不作修改,客户程序就无法重复此请求. HTTP 错误 401 401.1 未授权:登录失败 此错误表明传输给服务器的证 ...

  5. JavaService wrapper

    http://my.oschina.net/yjwxh/blog/260835 http://blog.chinaunix.net/uid-664509-id-3398193.html http:// ...

  6. 【UVALive - 3487】 Duopoly(网络流-最小割)

    Description The mobile network market in country XYZ used to be dominated by two large corporations, ...

  7. 【UVA11324】The Largest Clique (SCC)

    题意: 给一张有向图G,求一个结点数最大的结点集,使得该结点中任意两个结点 u 和 v满足:要么 u 可以到达 v, 要么 v 可以到达 u(u 和 v 相互可达也可以). 分析: Tarjan求SC ...

  8. [topcoder]UnsealTheSafe

    http://community.topcoder.com/stat?c=problem_statement&pm=4471&rd=10711 这题果然是道简单题,图+DP.拿道题便觉 ...

  9. Delphi常用排序

    1.冒泡排序 Delphi/Pascal code   ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 procedure BubbleSort(var x:a ...

  10. HDU --2665

    Kth number Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...