-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11_daum_movies.py
29 lines (21 loc) · 987 Bytes
/
11_daum_movies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import requests
from bs4 import BeautifulSoup
# 다음 사이트의 역대 관객순위를 연도별, 상위 5개의 이미지를 저장하기 2:41:10
for year in range(2015, 2021):
url = "https://search.daum.net/search?w=tot&q={}%EB%85%84%EC%98%81%ED%99%94%EC%88%9C%EC%9C%84&DA=MOR&rtmaxcoll=MOR".format(year)
res = requests.get(url)
res.raise_for_status()
soup = BeautifulSoup(res.text, "lxml")
images = soup.find_all("img", attrs={"class":"thumb_img"})
for idx, image in enumerate(images):
# print(image["src"])
image_url = image["src"]
if image_url.startswith("//"):
image_url = "https:" + image_url
print(image_url)
image_res = requests.get(image_url)
image_res.raise_for_status()
with open("movie_{}_{}.jpg".format(year, idx + 1), "wb") as f:
f.write(image_res.content)
if idx >= 4: # 상위 5개까지의 이미지만 다운로드
break