python模块imghdr读图片后缀名

转:https://blog.csdn.net/haipengdai/article/details/48713791


爬数据的时候常常遇到img标签的src中不包含图片的后缀名,这时通过imghdr模块就能够把图片的后缀名读出来。

  1. import urllib2  
  2. import imghdr  
  3.   
  4. url = 'http://photos.prnewswire.com/prn/20100819/LA52539LOGO'  
  5. response = urllib2.urlopen(url)  
  6. webpage = response.read()  
  7. print imghdr.what('', webpage)  


猜你喜欢

转载自blog.csdn.net/m0_37407756/article/details/80758323