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

  采集分析见 采集练习(五) 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()
posted @ 2013-03-11 23:29  keygle  阅读(793)  评论(0编辑  收藏  举报