使用python3批量下載rbsp數(shù)據(jù)的示例代碼
1. 原始網(wǎng)站
https://www.rbsp-ect.lanl.gov/data_pub/rbspa/
2. 算法說(shuō)明
進(jìn)入需要下載的數(shù)據(jù)所在的目錄,獲取并解析該目錄下的信息,解析出cdf文件名后,將cdf文件下載到內(nèi)存中,隨后保存到硬盤中。程序使用python3實(shí)現(xiàn)。
3. 程序代碼
#!/bin/python3
# get the rbsp data
# writen by Liangjin Song on 20191219
import sys
import requests
from pathlib import Path
# the url containing the cdf files
url="https://www.rbsp-ect.lanl.gov/data_pub/rbspa/ECT/level2/2016/"
# local path to save the cdf file
path="/home/liangjin/Downloads/test/"
def main():
re=requests.get(url)
html=re.text
cdfs=resolve_cdf(html)
ncdf=len(cdfs)
if ncdf == 0:
return
print(str(ncdf) + " cdf files are detected.")
i=1
# download
for f in cdfs:
rcdf=url+f
lcdf=path+f
print(str(i)+ " Downloading " + rcdf)
download_cdf(rcdf,lcdf)
i+=1
return
# resolve the file name of cdf
def resolve_cdf(html):
cdfs=list()
head=html.find("href=")
if head == -1:
print("The cdf files not found!")
return cdfs
leng=len(html)
while head != -1:
tail=html.find(">",head,leng)
# Extract the cdf file name
cdf=html[head+6:tail-1]
head=html.find("href=",tail,leng)
if cdf.find('cdf') == -1:
continue
cdfs.append(cdf)
return cdfs
def download_cdf(rcdf,lcdf):
rfile=requests.get(rcdf)
with open(lcdf,"wb") as f:
f.write(rfile.content)
f.close()
return
if __name__ == "__main__":
lpath=Path(path)
if not lpath.is_dir():
print("Path not found: " + path)
sys.exit(0)
sys.exit(main())
4. 使用說(shuō)明
url為遠(yuǎn)程cdf文件所在路徑。
path為本地保存cdf文件的路徑。
url和path的末尾都有“/”(Linux下情形,若是Windows,路徑分隔符為“\\”,則path末尾應(yīng)為“\\”)。
5. 運(yùn)行效果

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Python爬蟲實(shí)戰(zhàn)案例之爬取喜馬拉雅音頻數(shù)據(jù)詳解
- python爬蟲智能翻頁(yè)批量下載文件的實(shí)例詳解
- 用python批量下載apk
- python 根據(jù)列表批量下載網(wǎng)易云音樂(lè)的免費(fèi)音樂(lè)
- 用python爬蟲批量下載pdf的實(shí)現(xiàn)
- python FTP批量下載/刪除/上傳實(shí)例
- 如何基于Python批量下載音樂(lè)
- python爬蟲 批量下載zabbix文檔代碼實(shí)例
- python實(shí)現(xiàn)抖音視頻批量下載
- python+POP3實(shí)現(xiàn)批量下載郵件附件
- python實(shí)現(xiàn)壁紙批量下載代碼實(shí)例
- Python實(shí)現(xiàn)Youku視頻批量下載功能
- Python爬蟲之批量下載喜馬拉雅音頻
相關(guān)文章
python之PySide2安裝使用及QT Designer UI設(shè)計(jì)案例教程
這篇文章主要介紹了python之PySide2安裝使用及QT Designer UI設(shè)計(jì)案例教程,本篇文章通過(guò)簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-07-07
Python 尋找局部最高點(diǎn)的實(shí)現(xiàn)
今天小編就為大家分享一篇Python 尋找局部最高點(diǎn)的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-12-12
django數(shù)據(jù)庫(kù)自動(dòng)重連的方法實(shí)例
這篇文章主要給大家介紹了關(guān)于django數(shù)據(jù)庫(kù)自動(dòng)重連的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用django具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07
anaconda中安裝的python環(huán)境中沒(méi)有pip3的問(wèn)題及解決
這篇文章主要介紹了anaconda中安裝的python環(huán)境中沒(méi)有pip3的問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02
Pygame游戲開(kāi)發(fā)之太空射擊實(shí)戰(zhàn)添加圖形篇
相信大多數(shù)8090后都玩過(guò)太空射擊游戲,在過(guò)去游戲不多的年代太空射擊自然屬于經(jīng)典好玩的一款了,今天我們來(lái)自己動(dòng)手實(shí)現(xiàn)它,在編寫學(xué)習(xí)中回顧過(guò)往展望未來(lái),在本課中,我們將討論如何在游戲中使用預(yù)先繪制的圖形2022-08-08
PyQt5+python3+pycharm開(kāi)發(fā)環(huán)境配置教程
這篇文章主要介紹了PyQt5+python3+pycharm開(kāi)發(fā)環(huán)境配置教程,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-03-03
Python如何根據(jù)頁(yè)碼處理PDF文件的內(nèi)容
在Python中,fitz庫(kù)可以用于多種任務(wù),如打開(kāi)PDF文件、遍歷頁(yè)面、添加注釋、提取文本、旋轉(zhuǎn)頁(yè)面等,此外,它還可以用于在PDF頁(yè)面上添加高亮注釋、提取圖像等操作,這篇文章主要介紹了Python根據(jù)頁(yè)碼處理PDF文件的內(nèi)容,需要的朋友可以參考下2024-06-06

