강의

멘토링

커뮤니티

Inflearn Community Q&A

spdlqj5050537's profile image
spdlqj5050537

asked

Introduction to Python and Creating Various Automated Applications Using Web Crawling

How to use BeautifulSoup and Basic Web Parsing (2)

13분 16초 li:nth-of-type(8) 질문

Written on

·

277

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")

print("1",soup.select_one("li:nth-of-type(8)").string)

에러

Traceback (most recent call last):
  File "C:\Users\User0\Desktop\code\section2\download2-6-2.py", line 25, in <module>
    print("1",soup.select_one("li:nth-of-type(8)").string)
AttributeError: 'NoneType' object has no attribute 'string'
[Finished in 0.181s]

이렇게 에러나면서 실행이 안되는데 어떤문제때문에 안되는건가요??

python웹-크롤링

Answer 1

0

niceman님의 프로필 이미지
niceman
Instructor

안녕하세요.

해당 예제는 공지 보시면 새로운 예제 소스코드로 변경해서 올렸습니다.

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

2-6-2_new 입니다.

위에 링크 확인 부탁드려요!

spdlqj5050537's profile image
spdlqj5050537

asked

Ask a question