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

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. javascript 跨域请求详细分析(终极跨域解决办法)

    自从我接触前端以来,接手的项目里面很大部分都是前后端分离的,后端只提供接口,前端根据后端接口渲染出实际页面.个人觉得这是一个挺好的模式,前后端各自负责各自的模块,分工明确,而且也给前端更大的发挥空间. ...

  2. STL next_permutation 算法原理和实现

    转载自:https://www.cnblogs.com/luruiyuan/p/5914909.html 目标 STL中的next_permutation 函数和 prev_permutation 两 ...

  3. 前端修炼の道 | <div> 标签简介

    <div> 标签是最基本的,同时也是最常用的标签. 该标签是一个双标签,出现在主体区域中,主要作为一个容器标签来使用,在 <div> 标签中可以包含除 <body> ...

  4. Python 进程池的异步方法

    import time from multiprocessing import Process,Pool def f1(n): time.sleep(0.5) # print(n) return n* ...

  5. 【oracle入门】Oracle数据库11g企业版主要优点

    高可靠性.能够尽可能地放置服务器故障.站点故障和人为错误的发生. 高安全信息.可以利用行级安全性.细粒度审计.透明的数据加密和数据的全面会议确保数据安全和遵守法规. 更好的数据管理.轻松管理最大型数据 ...

  6. 使用selenium爬取网站动态数据

    处理页面动态加载的爬取 selenium selenium是python的一个第三方库,可以实现让浏览器完成自动化的操作,比如说点击按钮拖动滚轮等 环境搭建: 安装:pip install selen ...

  7. tree-lstm初探

    https://zhuanlan.zhihu.com/p/35252733 可以先看看上面知乎文章里面的例子 Socher 等人于2012和2013年分别提出了两种区分词或短语类型的模型,即SU-RN ...

  8. Java 11 Tutorial

    Java 11 Tutorial 参考 https://blog.csdn.net/sihai12345/article/details/82889827 原文 https://winterbe.co ...

  9. PythonStudy——Python 中Switch-Case 结构的实现

    学习Python过程中,发现Python没有Switch-case,过去写C习惯用Switch/Case语句,官方文档说通过if-elif实现.所以不妨自己来实现Switch-Case功能. 方法一 ...

  10. 什么是web前端开发?

    Web前端开发工程师,主要职责是利用(X)HTML/CSS/JavaScript/Flash等各种Web技术进行客户端产品的开发.完成客户端程序(也就是浏览器端)的开发,开发JavaScript以及F ...