抓取高速公路摄像照片
2016-03-17 11:25
483 查看
抓取某省所有高速公路上摄像头所拍下的照片,并保存到本地。
根据抓包每张拍摄到的照片的链接地址,可以知道,摄像头的设备id,是照片链接中最重要的参数。同时也可以查看网页加载的js文件中,后台程序是怎样构造照片的链接地址。
所以第一步是获取所有 摄像头的 deviceID,
然后构造照片的链接。
下载照片的二进制数据,保存到本地为照片。
其中,以上的url地址没具体写明
python 2.7
根据抓包每张拍摄到的照片的链接地址,可以知道,摄像头的设备id,是照片链接中最重要的参数。同时也可以查看网页加载的js文件中,后台程序是怎样构造照片的链接地址。
所以第一步是获取所有 摄像头的 deviceID,
然后构造照片的链接。
下载照片的二进制数据,保存到本地为照片。
#coding:utf-8 import json import requests import os import time from datetime import datetime import re class getCameraID: def __init__(self): self.url = "http://url----/gzcx/map/getAllCameraInfo.do" def getID(self): resp = requests.get(self.url) data = json.loads(resp.text) #resp.text 文本响应 # print len(data) ID_list = [] for i in xrange(len(data)): ID_list.append(data[i].get("deviceid","")) return ID_list class getPic: def __init__(self,cameraID_list): self.pre_url = "http://url----/gzcx/camera/" self.url_list = [] for camera_id in cameraID_list: self.url_list.append(self.pre_url+camera_id+".bmp") def getPicture(self, path="./temp"): t_note = datetime.now() time_note = t_note.strftime("%F_%H-%M-%S") path = path + time_note path = path.strip() if not os.path.exists(path): os.mkdir(path) i = 0 for url in self.url_list: resp = requests.get(url) data = resp.content #二进制响应 save_file(name=str(i)+".jpg", data=data, path=path) i += 1 def save_file(name,data,path): f = open(path+"/"+name, 'wb') f.write(data) f.flush() f.close() if __name__ == "__main__": start_time = time.clock() start_time1 = time.asctime(time.localtime(time.time())) print "cpu time", start_time print "start_time1",start_time1 cameraID = getCameraID() cameraID_list = cameraID.getID() getPicture = getPic(cameraID_list) getPicture.getPicture() end_time = time.clock() print "cpu time 2", end_time end_time1 = time.asctime(time.localtime(time.time())) print "end_time1", end_time1
其中,以上的url地址没具体写明
python 2.7
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- 爬虫笔记
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- python 类中的某个函数作为装饰器