_N_了吧唧的_ 发表于 2018-8-12 10:13:22

Python 批量下载图片示例

#!/usr/bin/env python  
import time
  
import urllib
  
i = 0
  
url = ['']*10
  
name = ['']*10
  
con = urllib.urlopen('http://www.ithome.com/html/bizhi/164396.htm').read()
  
src = con.find(r'/newsuploadfiles')
  
end = con.find(r'.jpg',src)
  
name = con
  
while src != -1 and end != -1 and i < 10:
  
    url = con
  
    src = con.find(r'/newsuploadfiles',end)
  
    end = con.find(r'.jpg',src)
  
    content = urllib.urlopen(url).read()
  
    open(r'img/'+ name+'jpg','w+').write(content)
  
    name = con
  
    print url
  
    time.sleep(3)
  
    i = i + 1
  
else:
  
    print "Download Over!"
页: [1]
查看完整版本: Python 批量下载图片示例