Python实现的图片批量下载(v3.5最新)

网上的版本太旧,更改如下:

#coding=utf-8
#Python v3.5
import urllib.request
import re

def getHtml(url):
    html = urllib.request.urlopen(url).read()
  #  print (html)
    return repr(html)

def getImg(html):
    reg = r"[a-zA-z]+://[^\s]*.jpg"
    imgre = re.compile(reg)
    imglist = re.findall(imgre,html)
    print (imglist)
    x = 0
    for imgurl in imglist:
        
        urllib.request.urlretrieve(imgurl,'%s.jpg' % x)
        x+=1
        return imgurl

html = getHtml("http://tieba.baidu.com/p/2460150866")

getImg(html)



你可能感兴趣的:(Python实现的图片批量下载(v3.5最新))