python学习笔记-抓取网页图片脚本

初学者一枚,代码都是模仿网上的。亲测可用~

运行脚本的前提是本机安装了httplib2模块

#!/usr/bin/python
import os
import re
import string
import urllib
#author:reed
#date:2014-05-14
def GetWebPictures():
    url=raw_input(‘please input the website you want to download:‘)
    imgcontent=urllib.urlopen(url).read()
    urllist=re.findall(r‘src="(http.+?\.jpg)"‘,imgcontent,re.I)
    if not urllist:
        print ‘not found...‘
    else:
        filepath=os.getcwd()+‘\img1‘
        if os.path.exists(filepath) is False:
            os.mkdir(filepath)
        x=1
        print ‘begin to get pictures...‘
        for imgurl in urllist:
            temp=filepath+‘\%s.jpg‘ % x
            print ‘it is downloading the %s pictures‘% x
            print imgurl
            urllib.urlretrieve(imgurl,temp)
            x+=1
    print ‘download completely...is saved at ‘+filepath
GetWebPictures()


本文出自 “[root@卢伟开51cto博客~]#” 博客,请务必保留此出处http://luweikai.blog.51cto.com/1705672/1411363

python学习笔记-抓取网页图片脚本,布布扣,bubuko.com

python学习笔记-抓取网页图片脚本

上一篇:Merkle 树——空间换时间,分而治之的hash表,通过根节点是由它的两个子节点内容的哈希值组成来校验数据完整性,定位篡改的数据位置


下一篇:java并发编程之Guarded Suspention