使用python3批量下載rbsp數(shù)據(jù)的示例代碼
1. 原始網(wǎng)站
https://www.rbsp-ect.lanl.gov/data_pub/rbspa/
2. 算法說明
進入需要下載的數(shù)據(jù)所在的目錄,獲取并解析該目錄下的信息,解析出cdf文件名后,將cdf文件下載到內(nèi)存中,隨后保存到硬盤中。程序使用python3實現(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. 使用說明
url為遠程cdf文件所在路徑。
path為本地保存cdf文件的路徑。
url和path的末尾都有“/”(Linux下情形,若是Windows,路徑分隔符為“\\”,則path末尾應為“\\”)。
5. 運行效果

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

