好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

python下载图片实现方法(超简单)

这篇文章介绍的内容是python下载图片实现方法(超简单),有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

#coding=utf-8
  import urllib
  def getHtml(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html
  html = getHtml("https://tieba.baidu测试数据/p/5582243679")
  print html 
import re
  import urllib
  def getHtml(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html
  def getImg(html):
    reg = r'src="(.+?\.jpg)" pic_ext'
    imgre = re测试数据pile(reg)
    imglist = re.findall(imgre,html)
    return imglist
  html = getHtml("https://tieba.baidu测试数据/p/5582243679")
  print getImg(html) 
#coding=utf-8
  import urllib
  import re
  def getHtml(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html
  def getImg(html):
    reg = r'src="(.+?\.jpg)" pic_ext'
    imgre = re测试数据pile(reg)
    imglist = re.findall(imgre,html)
    x = 0
    for imgurl in imglist:
      urllib.urlretrieve(imgurl,'%s.jpg' % x)
      x+=1
  html = getHtml("https://tieba.baidu测试数据/p/5582243679")
  print getImg(html) 
 import urllib.request
response = urllib.request.urlopen('http://HdhCmsTestg/500/600')
cat_img = response.read()

with open('cat_500_600.jpg','wb') as f:
 f.write(cat_img) 

以上就是python下载图片实现方法(超简单)的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于python下载图片实现方法(超简单)的详细内容...

  阅读:44次