当前位置:Gxlcms > Python > Python下载指定页面上图片

Python下载指定页面上图片

时间:2021-07-01 10:21:17 帮助过:62人阅读

本文实例讲述了Python下载指定页面上图片的方法。分享给大家供大家参考,具体如下:

  1. #!/usr/bin/python
  2. #coding:utf8
  3. import re
  4. import urllib
  5. def getHtml(url):
  6. page = urllib.urlopen(url)
  7. html = page.read()
  8. return html
  9. def getImg(html):
  10. reg = r'src="(.*?\.jpg)" '
  11. imgre = re.compile(reg)
  12. imglist = re.findall(imgre,html)
  13. x = 0
  14. for imgurl in imglist:
  15. urllib.urlretrieve(imgurl,'%s.jpg' % x)
  16. x += 1
  17. html = getHtml("http://tieba.baidu.com/p/2394357724")
  18. getImg(html)


更多Python下载指定页面上图片相关文章请关注PHP中文网!

人气教程排行