av一区二区在线观看_亚洲男人的天堂网站_日韩亚洲视频_在线成人免费_欧美日韩精品免费观看视频_久草视

您的位置:首頁技術文章
文章詳情頁

python 爬取天氣網衛星圖片

瀏覽:8日期:2022-06-17 11:04:40
目錄項目地址:代碼部分下載生成文件功能創建文件夾生成時間列表生成下載URL列表主函數爬取效果項目地址:

https://github.com/MrWayneLee/weather-demo

代碼部分下載生成文件功能

# 下載并生成文件def downloadImg(imgDate, imgURLs, pathName): a,s,f = 0,0,0 timeStart = time.time() while a < len(imgURLs):req = requests.get(imgURLs[a])imgName = str(imgURLs[a])[-13:-9]print(str('開始請求' + imgDate + ' ' + imgName + '的數據'))if req.status_code == 200: open(pathName + ’’ + os.path.basename(imgName) + ’.png’, ’wb’).write(req.content) print('數據' + imgDate + ' ' + imgName + '下載完成') s += 1 del reqelif req.status_code == 404: print('數據' + imgDate + ' ' + imgName + '不存在') f += 1a += 1 timeEnd = time.time() totalTime = round(timeEnd - timeStart, 2) print('全部數據請求完成!總耗時:',totalTime,'秒') print('共請求', a, '次;成功', s, '次;失敗', f, '次')創建文件夾

def createFolder(pathName): imgName_Year = pathName[0:4] imgName_Month = pathName[4:6] imgName_Day = pathName[6:8] imgName_date = imgName_Year + ’-’ + imgName_Month + ’-’ + imgName_Day mainPath = ’F:[Wayne Lee]學習資料Python爬取圖像’ newPathName = mainPath + ’’ + imgName_date realPath = newPathName + ’’ isExists = os.path.exists(newPathName) if not isExists:os.makedirs(newPathName)print('新文件夾 [' + imgName_date + '] 創建成功')return realPath else:print(pathName + '文件夾已存在')return realPath生成時間列表

def generateTime(imgUrl): timeList = [] imgUrlList = [] h,j = 0,0 while h < 24:m = 0while m < 60: timeList.append('{:0>4d}'.format(h * 100 + m)) m += 15h += 1 # print(timeList) # print(len(timeList)) while j < len(timeList):imgUrlList.append(str(imgUrl + timeList[j] + '00000.JPG'))# print(timeList[j])j += 1 return imgUrlList # print(imgUrlList) # print(len(imgUrlList))生成下載URL列表

def downloadUrl(imgDate): imgUrl = 'http://image.nmc.cn/product/' + imgDate[0:4] + '/' + imgDate[4:6] + '/' + imgDate[6:8] + '/WXBL/SEVP_NSMC_WXBL_FY4A_ETCC_ACHN_LNO_PY_' + imgDate # + '0000' +'00000.JPG' URLlist = list(generateTime(imgUrl)) return URLlist主函數

# 主函數if __name__ == ’__main__’: # imgUrl = 'http://image.nmc.cn/product/2020/04/11/WXBL/SEVP_NSMC_WXBL_FY4A_ETCC_ACHN_LNO_PY_20200411044500000.JPG' # imgUrl = 'http://image.nmc.cn/product/2020/04/11/WXBL/SEVP_NSMC_WXBL_FY4A_ETCC_ACHN_LNO_PY_20200411' # imgName = imgUrl[-21:-9] while True:print('[1]手動輸入日期')print('[2]獲取當天日期')print('[3]退出程序')choose = str(input('你的選擇:'))if choose == '1': imgDate = str(input('請輸入日期[如20200411]:')) urlList = list(downloadUrl(imgDate)) breakelif choose == '2': imgDate = time.strftime('%Y%m%d',time.localtime()) urlList = list(downloadUrl(imgDate)) breakelif choose == '3': breakelse: print('你的選擇有誤!請重試')

開始下載

pathName = createFolder(imgDate) # 開始下載 downloadImg(imgDate, urlList, pathName)

完整代碼

import requestsimport timeimport datetimeimport os# 下載并生成文件def downloadImg(imgDate, imgURLs, pathName): a,s,f = 0,0,0 timeStart = time.time() while a < len(imgURLs):req = requests.get(imgURLs[a])imgName = str(imgURLs[a])[-13:-9]print(str('開始請求' + imgDate + ' ' + imgName + '的數據'))if req.status_code == 200: open(pathName + ’’ + os.path.basename(imgName) + ’.png’, ’wb’).write(req.content) print('數據' + imgDate + ' ' + imgName + '下載完成') s += 1 del reqelif req.status_code == 404: print('數據' + imgDate + ' ' + imgName + '不存在') f += 1a += 1 timeEnd = time.time() totalTime = round(timeEnd - timeStart, 2) print('全部數據請求完成!總耗時:',totalTime,'秒') print('共請求', a, '次;成功', s, '次;失敗', f, '次')# 創建文件夾def createFolder(pathName): imgName_Year = pathName[0:4] imgName_Month = pathName[4:6] imgName_Day = pathName[6:8] imgName_date = imgName_Year + ’-’ + imgName_Month + ’-’ + imgName_Day mainPath = ’F:[Wayne Lee]學習資料Python爬取圖像’ newPathName = mainPath + ’’ + imgName_date realPath = newPathName + ’’ isExists = os.path.exists(newPathName) if not isExists:os.makedirs(newPathName)print('新文件夾 [' + imgName_date + '] 創建成功')return realPath else:print(pathName + '文件夾已存在')return realPath# 生成時間列表def generateTime(imgUrl): timeList = [] imgUrlList = [] h,j = 0,0 while h < 24:m = 0while m < 60: timeList.append('{:0>4d}'.format(h * 100 + m)) m += 15h += 1 # print(timeList) # print(len(timeList)) while j < len(timeList):imgUrlList.append(str(imgUrl + timeList[j] + '00000.JPG'))# print(timeList[j])j += 1 return imgUrlList # print(imgUrlList) # print(len(imgUrlList))# 生成下載URL列表def downloadUrl(imgDate): imgUrl = 'http://image.nmc.cn/product/' + imgDate[0:4] + '/' + imgDate[4:6] + '/' + imgDate[6:8] + '/WXBL/SEVP_NSMC_WXBL_FY4A_ETCC_ACHN_LNO_PY_' + imgDate # + '0000' +'00000.JPG' URLlist = list(generateTime(imgUrl)) return URLlist# 主函數if __name__ == ’__main__’: # imgUrl = 'http://image.nmc.cn/product/2020/04/11/WXBL/SEVP_NSMC_WXBL_FY4A_ETCC_ACHN_LNO_PY_20200411044500000.JPG' # imgUrl = 'http://image.nmc.cn/product/2020/04/11/WXBL/SEVP_NSMC_WXBL_FY4A_ETCC_ACHN_LNO_PY_20200411' # imgName = imgUrl[-21:-9] while True:print('[1]手動輸入日期')print('[2]獲取當天日期')print('[3]退出程序')choose = str(input('你的選擇:'))if choose == '1': imgDate = str(input('請輸入日期[如20200411]:')) urlList = list(downloadUrl(imgDate)) breakelif choose == '2': imgDate = time.strftime('%Y%m%d',time.localtime()) urlList = list(downloadUrl(imgDate)) breakelif choose == '3': breakelse: print('你的選擇有誤!請重試') # 創建文件夾 pathName = createFolder(imgDate) # 開始下載 downloadImg(imgDate, urlList, pathName)爬取效果

python 爬取天氣網衛星圖片

以上就是python 爬取天氣網衛星圖片的詳細內容,更多關于python 爬取天氣網圖片的資料請關注好吧啦網其它相關文章!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 一区二区三区精品视频 | 欧美日本一区二区 | 黄色在线免费观看视频网站 | 中文字幕一区二区三区在线观看 | 免费成年网站 | 99精品一区二区 | 国产成人网 | 这里精品 | 日本精品免费在线观看 | 午夜久久久久久久久久一区二区 | 色呦呦在线 | 日韩精品在线看 | 国产69精品久久99不卡免费版 | 96av麻豆蜜桃一区二区 | 亚洲国产欧美91 | 欧美日产国产成人免费图片 | 国产成视频在线观看 | 国产精品久久久久久久久免费相片 | 天天曰夜夜 | 亚洲欧美在线视频 | 青青草一区 | 欧美精品一区二区三区蜜臀 | 黄色网址在线免费观看 | 美女视频三区 | 久久神马| 日本一区二区高清不卡 | 亚洲永久 | 欧美日韩亚洲系列 | 成人a在线观看 | 福利色导航 | 91精品国产自产在线老师啪 | 久久综合爱| 日韩精品一二三 | 精品日韩 | 日本a∨精品中文字幕在线 亚洲91视频 | 亚洲a在线视频 | 日韩在线视频一区 | 成人性视频免费网站 | 99精品国产一区二区三区 | 99热热热| 国产精品一二三区 |