使用python3批量下載rbsp數(shù)據(jù)的示例代碼
1. 原始網(wǎng)站
https://www.rbsp-ect.lanl.gov/data_pub/rbspa/
2. 算法說明
進(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. 使用說明
url為遠(yuǎn)程cdf文件所在路徑。
path為本地保存cdf文件的路徑。
url和path的末尾都有“/”(Linux下情形,若是Windows,路徑分隔符為“\\”,則path末尾應(yīng)為“\\”)。
5. 運(yùn)行效果
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Python爬蟲實(shí)戰(zhàn)案例之爬取喜馬拉雅音頻數(shù)據(jù)詳解
- python爬蟲智能翻頁批量下載文件的實(shí)例詳解
- 用python批量下載apk
- python 根據(jù)列表批量下載網(wǎng)易云音樂的免費(fèi)音樂
- 用python爬蟲批量下載pdf的實(shí)現(xiàn)
- python FTP批量下載/刪除/上傳實(shí)例
- 如何基于Python批量下載音樂
- 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制作簡單的樸素基數(shù)估計(jì)器的教程
這篇文章主要介紹了用Python制作簡單的樸素基數(shù)估計(jì)器的教程,同時(shí)介紹了如何去改進(jìn)精度來進(jìn)行算法優(yōu)化,需要的朋友可以參考下2015-04-04Python實(shí)現(xiàn)將Excel內(nèi)容插入到Word模版中
前段時(shí)間因?yàn)樾枰幚硪淮蠖羊?yàn)收單,都是一些簡單的復(fù)制粘貼替換工作,于是就想到用python進(jìn)行處理。本文分享了用python將excel文件單元格內(nèi)容插入到word模版中并保存為新文件的辦法,希望對大家有所幫助2023-03-03教你使用Python建立任意層數(shù)的深度神經(jīng)網(wǎng)絡(luò)
這篇文章主要介紹了Python建立任意層數(shù)的深度神經(jīng)網(wǎng)絡(luò),本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-08-08springboot整合單機(jī)緩存ehcache的實(shí)現(xiàn)
本文主要介紹了springboot整合單機(jī)緩存ehcache的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02python實(shí)現(xiàn)多層感知器MLP(基于雙月數(shù)據(jù)集)
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)多層感知器MLP,基于雙月數(shù)據(jù)集,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01