进行图片下载,需要提前准备好下载图片的存放文件夹;

python在与文件、目录打交道时,少不了os模块。os模块包含普遍的操作系统功能。

os.path.exists(filepath)——检验指定的对象是否存在;os.mkdir(filepath)——创建目录;os.path.join(path, name)——连接目录和文件名


 import os
import sys #city_id = sys.argv[1]
city_id = 660 def check_make_image_floder(filepath):
if not os.path.exists(filepath):
os.makedirs(filepath)
image_floder = "C:\\Users\\admin\\Desktop\\%s" %city_id
check_make_image_floder(image_floder)
urllib.urlretrieve(url, filename)—将远程数据下载到本地指定路径

 import os
import sys
import urllib #city_id = sys.argv[1]
city_id = 660 def check_make_image_floder(filepath):
if not os.path.exists(filepath):
os.makedirs(filepath)
image_floder = "C:\\Users\\admin\\Desktop\\%s" %city_id
check_make_image_floder(image_floder) filename = "660170120991757571.jpg"
dest_dir = os.path.join(image_floder,filename) url_example = 'http://xxx.xxx.xx.xxx:xxxx/REST/docService?timestamp=1450063392000&organId=xxxxx&busiType=1&appId=crmlog&staffNo=xxTEST200&filename=660/16000004/13298809/660170120991757571.jpg&method=get&password=crmlog1452&latnId=660&signature=731ccc37de5e48dc69bb9ba3xxxxxxxxx&version=001'
def crawl_image(url_example,dest_dir):
urllib.urlretrieve(url_example,dest_dir) crawl_image(url_example,dest_dir)

进行文件下载前,先替换latnId;

 import os
import sys
import urllib
import re #city_id = sys.argv[1]
city_id = 660 url_example = 'http://xxx.xxx.xx.xxx:xxxx/REST/docService?timestamp=1450063392000&organId=2222&busiType=1&appId=crmlog&staffNo=xxTEST200&filename=663/16000004/13298809/6601701209917xxxxx.jpg&method=get&password=crmlog1452&latnId=663&signature=731ccc37de5e48dc69bb9ba34b9f3188&version=001'
pattern = re.compile(r'latnId=\d{2,3}')
image_url01 = re.sub(pattern, 'latnId='+str(city_id).strip(), url_example) def check_make_image_floder(filepath):
if not os.path.exists(filepath):
os.makedirs(filepath)
image_floder = "C:\\Users\\admin\\Desktop\\%s" %city_id
check_make_image_floder(image_floder) def crawl_image(image_url,dest_dir):
urllib.urlretrieve(image_url,dest_dir) with open("C:\\Users\\admin\\Desktop\\%sdata.txt"%city_id,'r') as f:
lines = f.readlines()
lists = image_url01.split('&')
for list in lists:
if list.startswith('filename'):
for line in lines:
image_url02 = re.sub(list, 'filename='+line.strip(), image_url01)
results = line.split('/')
image_name_ex = results.pop()
image_info = urllib.urlopen(image_url02.strip())
if image_info.getcode() == 200:
image_url = image_url02.strip()
dest_dir = os.path.join(image_floder,image_name_ex.strip())
crawl_image(image_url,dest_dir)
print image_url + " write sucess !"

Python 程序下载经办人照片的更多相关文章

  1. python大法好——python的下载与安装、第一个程序

    吃够了java的苦,所以python好. 打今天起,要走python了. 首先呢,学习python需要python环境.和一款得心应手的集成开发环境. python环境下载:https://mirro ...

  2. 3.第一个python程序

    学习任何一门语言的第一步,首先要写个'hello world',这算是程序员的一个传统.但在写之前,还有注意几个问题. 首先,python是一门脚本语言,而脚本语言的特点就是:我们写的代码会先由解释器 ...

  3. 编写高质量代码改善python程序91个建议学习01

    编写高质量代码改善python程序91个建议学习 第一章 建议1:理解pythonic的相关概念 狭隘的理解:它是高级动态的脚本编程语言,拥有很多强大的库,是解释从上往下执行的 特点: 美胜丑,显胜隐 ...

  4. 介绍Python程序员常用的IDE和其它开发工具

    概述 “工欲善其事,必先利其器”,如果说编程是程序员的手艺,那么IDE就是程序员的吃饭家伙了. IDE 的全称是Integration Development Environment(集成开发环境), ...

  5. Python:使用Kivy将python程序打包为apk文件

    1.概述 Kivy是一套Python下的跨平台开源应用开发框架,官网,我们可以用 它来将Python程序打包为安卓的apk安装文件.以下是在windows环境中使用. 安装和配置的过程中会下载很多东西 ...

  6. 将Python程序打包为exe方法

    将Python程序打包为exe文件,需要使用到的工具是pyinstaller pyinstaller是一个多平台的Python程序打包为exe的免费工具 安装pyinstaller: 1,在Windo ...

  7. Jenkins简明入门(二) -- 利用Jenkins完成Python程序的build、test、deployment

    大家可能还没搞清楚,Jenkins到底能做什么? 本节内容利用Jenkins完成python程序的build.test.deployment,让大家对Jenkins能做的事情有一个直观的了解. 本节内 ...

  8. 改善python程序的建议[转]

    <编写高质量代码 改善Python程序的91个建议> <编写高质量代码 改善Python程序的91个建议>读后程序学习小结 - BigDeng_2014的专栏 - CSDN博客 ...

  9. 编写python程序和运行.py文件的方法步骤

    前提:已安装好 Subliume Test 3 且已经添加好python编译系统,已安装好python3.7 一.新建一个文本文档,将后缀名改为.py 二.使用 Subliume Test 3 打开该 ...

随机推荐

  1. day 17 项目开发常用模块

    ---恢复内容开始--- time模块 import time print(time.time()) # 时间戳: print(time.strftime("%Y-%m-%d %X" ...

  2. Delphi xe8 FMX StringGrid根据内容自适应列宽。

    Delphi xe8 FMX StringGrid根据内容自适应列宽. 网上的资料比较复杂,而且不是根据字体字号等设置列宽.故自己写了个function来用. function GetColMaxDa ...

  3. 51单片机小项目电路TwoLed电路图

    1.复位电路没有开关,不可控 在电容旁边并联一个开关和10k的电阻支路 2.晶振电路引用的外部晶振, 理论上XTAL2悬空,XTAL1接外部震荡信号 //ProjeceName:TwoLed //wr ...

  4. FreeSWITCH与FreeSWITCH对接

    (主机A ---> 主机B)192.168.100.A主机:修改/usr/local/freeswitch/conf/dialplan/default.xml 10         <ex ...

  5. Unity用GUI绘制Debug/print窗口/控制台-打包后测试

    Unity游戏视窗控制台输出 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分享 ...

  6. 回顾HashMap

    一.HashMap的原理简述 HashMap是基于哈希表的非线程安全的Map实现,内部采用数组+链表实现,其内部类Node定义了数据元素类型,它扩展了Map.Entry<K,V>增加了指向 ...

  7. day11 大纲

    01 昨日内容回顾 函数名的运用: 1,特殊的变量. 2,函数名可以当做变量赋值. 3,函数名可以当做容器类类型的元素. 4,函数名可以当做函数的参数. 5,函数名可以当做函数的返回值. 函数的运用: ...

  8. 20175202 《Java程序设计》第四周学习总结

    20175202 <Java程序设计>第四周学习总结 第五章学习内容 1.子类的继承性: (1)子类与父类在同一包中的继承性:子类自然地继承了其父类中不是private的成员变量作为自己的 ...

  9. linux scp传输文件命令

    scp  -r /opt/test root@192.168.2.105:/opt

  10. repository test has failed 错误

    这里给自己一个警告,当我在idea中准备clone gitlab上的项目时,这个链接竟然一直在报:repository test has failed 错误 这个是gitlab上复制下来的原链接:ht ...