강의

멘토링

커뮤니티

Inflearn Community Q&A

whitedog3190861's profile image
whitedog3190861

asked

[Renewed] Python Introduction and Web Scraping Basics Bootcamp [Python, Web, Data Understanding Fundamentals] (Updated)

Pattern-based Practice and Learning: Learning Through Crawling Code Patterns 1

강의 내용 중 **.content에 대하여.

Resolved

Written on

·

197

0

강의 내용중 **.content 로 html을 불러 오는데, 

예전에 공부하다가 **.text로 html을 불러 올 수 있다고 들었는데, 

이 둘의 차이가 뭔가요? 아무거나 골라서 사용해도 무방한가요?

python웹-크롤링

Answer 1

2

funcoding님의 프로필 이미지
funcoding
Instructor

안녕하세요. 다음과 같이 코드를 작성할 때는 둘중 아무거나 선택해서 사용해도 무방합니다.

soup = BeautifulSoup(res.content, 'html.parser')

다만 둘은 데이터 타입이 다르긴 합니다.

res.content는 byte로 데이터를 표현하고 있고, res.text 는 string(문자열)로 데이터를 표현하고 있습니다.

BeautifulSoup() 클래스에서는 byte든 string이든 알아서 처리를 해주기 때문에, 둘 다 가능한 것입니다.

가볍게  다음과 같이 출력해보시면, 둘의 타입이 다르다는 점을 알 수 있습니다.

print (type(res.text), type(res.content))

감사합니다.

whitedog3190861's profile image
whitedog3190861

asked

Ask a question