本文实例讲述了python下载指定页面上图片的方法。分享给大家供大家参考,具体如下:
#!/usr/bin/python #coding:utf8import reimport urllibdef gethtml(url): page = urllib.urlopen(url) html = page.read() return htmldef getimg(html): reg = r'src=(.*?\.jpg) ' imgre = re.compile(reg) imglist = re.findall(imgre,html) x = 0 for imgurl in imglist: urllib.urlretrieve(imgurl,'%s.jpg' % x) x += 1html = gethtml(http://tieba.baidu.com/p/2394357724)getimg(html)
更多关于python相关内容感兴趣的读者可查看本站专题:《python图片操作技巧总结》、《python数据结构与算法教程》、《python socket编程技巧总结》、《python函数使用技巧总结》、《python字符串操作技巧汇总》、《python入门与进阶经典教程》及《python文件与目录操作技巧汇总》
希望本文所述对大家python程序设计有所帮助。