Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Python
Posted by: Mario Lopes
Added: Nov 18, 2018 5:16 PM
Views: 5
Download imagens do site para uma pasta
  1. #procura imagens
  2. import urllib.request
  3. import re
  4. req = urllib.request.Request("http://sapo.pt", headers={'User-Agent': 'Mozilla/5.0'})        
  5. htmltext = urllib.request.urlopen(req).read()
  6. if htmltext is None:
  7.     print("nada")
  8. else:
  9.     regex='<img src="/(.+?)"'
  10.     pattern=re.compile(regex)
  11.     imagem=pattern.findall(str(htmltext))
  12.     print(imagem[4])
  13. #descarrega imagem
  14. import urllib.request
  15. urllib.request.urlretrieve("http://sapo.pt/"+imagem[4], "c:\imagens\lopes.jpg")