인프런 영문 브랜드 로고
인프런 영문 브랜드 로고

Inflearn Community Q&A

cuzai8598's profile image
cuzai8598

asked

Introduction to Python and Creating Various Automated Applications Using Web Crawling

How to use BeautifulSoup and basic simple web parsing (2)

select_one 관련 에러

Written on

·

194

0

from bs4 import BeautifulSoup

import sys

import io

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

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

fp = open('food-list.html', encoding='utf-8')

soup = BeautifulSoup(fp, 'html.parser')

li = soup.select_one('li:nth-of-type(8)')

print(li.string)

로 정확히 코딩 했는데도 none type 에러가 납니다.

nth-of-type(5)로 했을 때 '동동주'가 나오는 것으로 봐서 전체 리스트 중 5번째가 아니라 두 번째(id가 ac-list)리스트에서 5번째를 가지고 오는 것 같습니다. 그래서 8번째에는 none이라고 뜨는게 아닐까요?

확인 부탁드립니다.

감사합니다.

python웹-크롤링

Answer 1

0

niceman님의 프로필 이미지
niceman
Instructor

안녕하세요.

해당 파일은 이미 수정 버전을 올려놨습니다. 공지에도 적어놨습니다.

https://github.com/eunki7/python_create_app_1/blob/master/section2/2-6-2_new_1.py

아래 소스를 확인부탁드립니다.

감사합니다.

cuzai8598's profile image
cuzai8598

asked

Ask a question