Python: Download Gambar dengan Resolusi Tertinggi dari Laman Web

Kali ini kita coba gunakan Python untuk mengunduh gambar dengan resolusi tertinggi dari laman web (web page) target.
import requests
from os.path  import basename
from bs4 import BeautifulSoup
from PIL import Image
import io
import matplotlib.pyplot as plt
import numpy as np

#URL target (disini ada beberapa gambar yang bisa di-download)
url = 'http://www.teknologi-bigdata.com/2019/08/buku-teknologi-big-data-edisi-revisi.html'
r = requests.get(url)
soup = BeautifulSoup(r.content)

max_res = 0
for link in soup.select('img[src^=http]'):
    
    lnk = link['src']
    img_bytes = requests.get(lnk).content
    img_file = Image.open(io.BytesIO(img_bytes))
    width, height = img_file.size
    resolution = width * height
    
    if max_res < resolution:
        max_res = resolution
        max_size = str(width) + 'x' + str(height)
        max_img_file = img_file

print('highest res = ' + str(max_res) + ', max size = ' + max_size)
max_img_file.save('featured_image.' + str(max_img_file.format))
print('featured_image saved')

#Tampilkan gambar yang sudah di-download dengan MatplotLib
plt.imshow(np.array(max_img_file))

highest res = 327680, max size = 512x640 featured_image saved

Berikut adalah gambar yang berhasil di-download dari URL target.



Comments

Natasha John said…
BTW, speaking of piling up data and assignments, it is really noticeable how much of a difference it makes when we have the right tools. It is like when I was in college, sometimes I was given assignments or research that were so technically demanding that I couldnt breathe. I used to wonder if there was a nursing dissertation writing service that could help me with the administrative and writing aspects, it would definitely be a huge help, allowing me to focus more on the core research.

Popular posts from this blog

Apache Spark: Perangkat Lunak Analisis Terpadu untuk Big Data

Apa itu Big Data : Menyimak Kembali Definisi Big Data, Jenis Teknologi Big Data, dan Manfaat Pemberdayaan Big Data

Aplikasi iPhone : RETaS Read English Tanpa Kamus!

Google Ngram: Alat Analisis Kata dan Tren Budaya dari Masa ke Masa

Kesalahan Kurs Google Finance: Tantangan Teknologi Big Data dalam Deteksi Anomali dan Akurasi Data Keuangan

MapReduce: Besar dan Powerful, tapi Tidak Ribet

Memahami Definisi Big Data

Tutorial Python: Cara Mudah Web Scraping menggunakan Beautiful Soup

Cara Sederhana Install Hadoop 2 mode Standalone pada Windows 7 dan Windows 10