-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.py
More file actions
26 lines (22 loc) · 767 Bytes
/
Copy pathExample.py
File metadata and controls
26 lines (22 loc) · 767 Bytes
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
from bs4 import BeautifulSoup as bs
from urllib.request import urlopen
from urllib.parse import quote_plus
baseUrl = 'https://search.naver.com/search.naver?where=image&sm=tab_jum&query='
plusUrl = input('검색어 입력: ')
crawl_num = int(input('크롤링할 갯수 입력(최대 50개): '))
url = baseUrl + quote_plus(plusUrl) # 한글 검색 자동 변환
html = urlopen(url)
soup = bs(html, "html.parser")
img = soup.find_all(class_='_img')
n = 1
for i in img:
print(n)
imgUrl = i['data-source']
with urlopen(imgUrl) as f:
with open('./pictures/img' + str(n) + '.jpg', 'wb') as h: # w - write b - binary
img = f.read()
h.write(img)
n += 1
if n > crawl_num:
break
print('Image Crawling is done.')