python URL模块实例
来源:互联网 发布:桶装水管理软件 编辑:程序博客网 时间:2024/06/04 20:08
再进行python编码过程中,需要对网站上图片进行下载保存到本地,以下实例实现将指定的图片下载保存到本地:
#!/usr/bin/python# -*- coding: UTF-8 -*-'''@author:freesigefeiCreated on 2016年3月11日'''#本模块作用为通过直接访问图片下载地址,直接将图片下载保存到本地import os,urllib#首先定义图片下载的网址,以及图片本地保存的文件夹地址 urlPath='http://192.168.1.1/logo' #根据文件名创建文件 def createFileWithFileName(localPathParam,fileName): '''根据文件名创建文件,localPathParam保存的本地路径,fileName保存的文件名''' totalPath=localPathParam+fileName if not os.path.exists(totalPath): Image_file=open(totalPath,'a+') Image_file.close() return totalPath #根据图片的地址,下载图片并保存在本地 def getAndSaveImg(imgUrl,fileName): '''将下载的图片保存到本地,imgUrl表示下载地址,fileName表示保存的文件名''' localPath='D:\\download\\' #localPath表示保存的本地路径 if( len(imgUrl)!= 0 ): urllib.urlretrieve(imgUrl,createFileWithFileName(localPath,fileName))if __name__ == '__main__': getAndSaveImg(urlPath,'Logo.jpg')通过运行本实例,可以将对应地址的logo图片下载到本地目录下
0 0
- python URL模块实例
- python包模块实例
- python logging模块实例
- python URLObject url处理模块
- NodeJs模块实例01_http和url
- python random模块与实例
- python smtp模块实例代码
- Python collections模块实例讲解
- Python collections模块实例讲解
- python log模块使用实例
- python csv模块使用实例
- python time模块使用实例
- Python collections模块实例讲解
- Python: os模块实例详解
- Python: Logging模块实例详解
- Python collections模块实例讲解
- Python collections模块实例讲解
- Python分解URL域名模块tldextract
- 优化UITableViewCell高度计算
- Android中IntentService源码分析及其使用
- 5、Java的多态
- [2016,CVPR] Learning Deep Feature Representations with Domain Guided Dropout for Person Re-id
- java字符串subString的实现
- python URL模块实例
- (Leetcode)5. Longest Palindromic Substring
- CSS3选择器详解二
- Bagging, Boosting, and Randomization对比
- [BZOJ3333]排队计划(离散化+树状数组+线段树)
- ios 微信分享,QQ分享,微博分享集成
- 第2章 分支出12章 第1章汇编概念
- UESTC 482 Charitable Exchange(优先队列+bfs)
- HDU 1166