728x90
반응형
After logging in on the pexels site and requesting image & video api, you can get a key.
I will proceed with the assumption that there is an api key.
pip install pexels-api-py
First, install pip install pexels-api-py.
import requests
import os
from pexelsapi.pexels import Pexels
pexel = Pexels('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') #api_key
search_photos = pexel.search_photos(query=f'{keyword}', orientation='', size='', color='', locale='', page=1, per_page=2)
print(search_photos.get('photos')[0].get('src'))
res = requests.get(search_photos.get('photos')[0].get('src').get('original'))
print(res.content)
folder_path = os.path.join(os.path.expanduser("~"), "Desktop", "pexelFolder")
if res.ok:
file_name = 'test_download.jpeg'
file_path = os.path.join(folder_path, file_name)
with open(file_path, "wb") as f:
f.write(res.content)
print(f"{file_name} file download success.")
That's it. It's that simple.
After executing the above code, you can see that the image is saved in the location you specified.
Then see you next time~

728x90
반응형
'Python' 카테고리의 다른 글
파이썬 초보자를 위한 기초프로그래밍 공부 방법 (33) | 2023.05.21 |
---|---|
[python] SSL: CERTIFICATE_VERIFY_FAILED (19) | 2023.05.19 |
VSCode에서 GitHub 연동하는 방법 쉽게 알아보기 (1) | 2023.05.14 |
[python]파이썬으로 구글 검색 결과 크롤링하기: 간단한 가이드 (8) | 2023.05.11 |
[python]티스토리 자동 포스팅 part3 (12) | 2023.04.30 |
댓글