MoonChaeyeon

naver image crawling program

1 +from urllib.request import urlopen
2 +from bs4 import BeautifulSoup as bs
3 +from urllib.parse import quote_plus
4 +
5 +baseUrl = 'https://search.naver.com/search.naver?where=image&sm=tab_jum&query='
6 +plusUrl = input('검색어를 입력하세요 : ')
7 +# 한글 검색 자동 변환
8 +url = baseUrl + quote_plus(plusUrl)
9 +html = urlopen(url)
10 +soup = bs(html, "html.parser")
11 +img = soup.find_all(class_='_img', limit = 20)
12 +
13 +n = 1
14 +for i in img:
15 + imgUrl = i['data-source']
16 + with urlopen(imgUrl) as f:
17 + with open('사진' + plusUrl + str(n)+'.jpg','wb') as h: # w - write b - binary
18 + img = f.read()
19 + h.write(img)
20 + n += 1
21 +print('다운로드 완료')
...\ No newline at end of file ...\ No newline at end of file
1 +from urllib.request import urlopen
2 +from bs4 import BeautifulSoup as bs
3 +from urllib.parse import quote_plus
4 +
5 +baseUrl = 'https://search.naver.com/search.naver?where=image&sm=tab_jum&query='
6 +plusUrl = input('검색어를 입력하세요 : ')
7 +# 한글 검색 자동 변환
8 +url = baseUrl + quote_plus(plusUrl)
9 +html = urlopen(url)
10 +soup = bs(html, "html.parser")
11 +img = soup.find_all(class_='_img', limit = 20)
12 +
13 +n = 1
14 +for i in img:
15 + imgUrl = i['data-source']
16 + with urlopen(imgUrl) as f:
17 + with open('사진' + plusUrl + str(n)+'.jpg','wb') as h: # w - write b - binary
18 + img = f.read()
19 + h.write(img)
20 + n += 1
21 +print('다운로드 완료')
...\ No newline at end of file ...\ No newline at end of file