강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

SeungMin Hyun님의 프로필 이미지
SeungMin Hyun

작성한 질문수

파이썬 입문 및 웹 크롤링을 활용한 다양한 자동화 어플리케이션 제작하기

BeautifulSoup 사용법 및 간단 웹 파싱 실습(2) - 네이버, 인프런

직전강의에도 질문드렸었는데

작성

·

216

0

다시 봐도 이상이 없습니다

f12를 눌러서 copy selector 하면

#main_pack > section > div > div.photo_group._listGrid > div.photo_tile._grid > div:nth-child(1) > div > div.thumb > a > img

가 나오고 여기서 저는

div.thumb > a > img를 선택 했습니다 

그러나 역시 결과는 저번 강의때와 마찬가지로 빈 리스트만 출력됩니다

from bs4 import BeautifulSoup

import urllib.request as req

import urllib.parse as rep

import sys

import io

import os

sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')

sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8')

base = "https://search.naver.com/search.naver?where=image&sm=tab_jum&query="

quote = rep.quote_plus("사자")

url = base + quote

res = req.urlopen(url)

savePath = "C:/python/img_down"

try:

    if not (os.path.isdir(savePath)):

        os.makedirs(os.path.join(savePath))

except OSError as e:

    if e.errno != errno.EEXIST:

        print("폴더 만들기 시패!")

        raise

soup = BeautifulSoup(res, "html.parser")

img_list = soup.select("div.thumb > a > img")

print("test", img_list)

test []
[Finished in 0.305s]

답변 1

0

좋은사람님의 프로필 이미지
좋은사람
지식공유자

안녕하세요.

영상 후반부에 나오는 selenium을 활용해서 크롤링하시면 됩니다.

확인해보니 현재 ajax 형식으로 변경된 듯 합니다.

SeungMin Hyun님의 프로필 이미지
SeungMin Hyun

작성한 질문수

질문하기