python批量下载壁纸

http://www.bathome.net/thread-18139-1-1.html

把这个脚本稍微修改了以下。


#! /usr/bin/env python

##python2.7-批量下载壁纸
##壁纸来自桌酷网站,所有权归属其网站
##本代码仅做为交流学习使用,请勿用于商业用途,否则后果自负
##Code by Broly

import re,urllib,urllib2,socket
import os






def get_picture(url):
    
    urlSource = urllib.urlopen(url).read()

    pattern = re.compile(r'<a href="(\d+\(\d+\)\.htm)" ', re.M | re.S)
    match = pattern.findall(urlSource)

    print match

    if match:
        for subUrl in match:
            print url[0:url.rfind('/')+1]+subUrl
            
            subUrlSource = urllib.urlopen(url[0:url.rfind('/')+1]+subUrl).read()
            sPattern = re.compile(r'var thunder_url = "(.*)";')
            
            picUrl = sPattern.findall(subUrlSource)[0]

            
            getPic = urllib2.Request(picUrl)
            getPic.add_header('Referer','http://www.zhuoku.com')
            
            f = open(savepath+picUrl[picUrl.rfind('/')+1:],'wb')
            f.write(urllib2.urlopen(getPic).read())
            f.close()
            
    print "All done."
if __name__=="__main__":
    #设置超时时间
    socket.setdefaulttimeout(30)
    #保存图片的路径
    savepath = 'e:\\picture\\'
    #壁纸集合的URL,如下
    url = 'http://www.zhuoku.com/zhuomianbizhi/game-gamewall/20120503162540.htm'

    if(os.path.exists(savepath)):
        get_picture(url)
        
    else:
        os.makedirs(savepath)
        print "createt the dirc for the picture"
        get_picture(url)
        




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值