您的位置:首页 > 编程语言 > Python开发

采集练习(六) python获得chrome扩展 微度新标签页 下的云壁纸

2013-03-11 23:29 405 查看
  采集分析见 采集练习(五) php 获得chrome扩展 微度新标签页 下的云壁纸(主要是美女壁纸)

以下是用python 实现同样的功能。

python 版本 2.73

以下是代码:

# -*- coding: utf-8 -*-
import urllib2,json,os
dir = "D:\python\weidu\images\\"
jsonUrl = "http://hao.weidunewtab.com/cloudWallpaper/index.json";
req = urllib2.Request(jsonUrl)
request = urllib2.urlopen(req).read();
jsonData = json.loads(request)
for i in jsonData:
nums = ''
nums = jsonData[i]
numList = nums.split('-')
imageDir = dir+i+'\\'
if not os.path.isdir(imageDir):
os.mkdir(imageDir)
for n in range(int(numList[1]),int(numList[0])+1):
imageUrl = ''
imageUrl = 'http://hao.weidunewtab.com/cloudWallpaper/'+str(i)+'/'+str(n)+'.jpg'
imageRe = urllib2.Request(imageUrl)
imageData = urllib2.urlopen(imageRe).read()
imageName = imageDir+str(n)+'.jpg'
file_object = open(imageName, 'wb')
file_object.write(imageData)
file_object.close()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: