본문 바로가기
Python

[Python] 빠른 이미지 다운로드 라이브러리 : urllib3

by bryan.oh 2021. 10. 26.
반응형

The fastest library for downloading image

 

특징

  • Thread safety.
  • Connection pooling.
  • Client-side SSL/TLS verification.
  • File uploads with multipart encoding.
  • Helpers for retrying requests and dealing with HTTP redirects.
  • Support for gzip, deflate, and brotli encoding.
  • Proxy support for HTTP and SOCKS.
  • 100% test coverage.

 

설치

python -m pip install urllib3

 

예제1

import urllib3
http = urllib3.PoolManager()
resp = http.request("GET", "http://httpbin.org/robots.txt")
resp.status
# 200
resp.data
# b"User-agent: *\nDisallow: /deny\n"

예제2

from PIL import Image
from io import BytesIO
import urllib3

http = urllib3.PoolManager()

image_url = 'http://...image url...'

r = http.request('GET', image_url, preload_content=False)
image = Image.open(BytesIO(r.read()))
r.release_conn()

 

공식 사이트

 

 

728x90
반응형

댓글