Skip to content

Instantly share code, notes, and snippets.

@kkoyun
Last active October 17, 2017 14:33
Show Gist options
  • Save kkoyun/18423287f08051e721b67aeb891cc47f to your computer and use it in GitHub Desktop.
Save kkoyun/18423287f08051e721b67aeb891cc47f to your computer and use it in GitHub Desktop.
requests modülüyle dosya çekip yazmak / downloading files with "requests" module and saving them
#!/usr/bin/env python3
# requests modülüyle ilgili detaylı açıklamalar (ingilizce) http://requests.readthedocs.io/ sitesinde
# mac OS'te Python'a eklemek için terminal penceresinde (Python 3.x için)
# pip3 install requests
# windows'ta ekleme için komut penceresinde
# pip install requests
import requests
urlListesi = ['http://www.planwallpaper.com/static/images/79438-blue-world-map_nJEOoUQ.jpg',
'http://www.planwallpaper.com/static/images/b807c2282ab0a491bd5c5c1051c6d312_rP0kQjJ.jpg',
'http://www.planwallpaper.com/static/images/city_of_love-wallpaper-1366x768.jpg']
say = 1
for url in urlListesi:
res = requests.get(url) #resmin siteden alınması
#içine yazılacak dosyanın bilgisayarda oluşturulması
dosya = open('resim' + str(say) + '.jpg', 'wb')
#dosyanın içine resmin parça parça yazılması
#Büyük dosyaların birkerede yazılması sorun yaratabileceği için
#parça parça yazılması özellikle tavsiye ediliyor.
topYaz = 0
for parca in res.iter_content(10**5):
topYaz += dosya.write(parca)
dosyaIsmi = dosya.name
dosya.close()
print('{0} dosyasına {1:,} bayt yazıldı.'.format(dosyaIsmi, topYaz))
say += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment