본문 바로가기

Web/python

[python] BeautifulSoup

파이썬을 이용한 웹 크롤링 시 데이터 추출하기 위한 함수

 

  • requests 설치
pip install requests
  • BeautifulSoup 설치
pip install beautifulsoup4

 

  • 파이썬에서 기본 내장함수가 아니라서 import 필요
import requests
from bs4 import eautifulSoup

 

  • 사용법
import requests
from bs4 import BeautifulSoup

url = 'https://naver.com'

res = requests.get(url)

if res.status_code == 200:
    html = res.text
    soup = BeautifulSoup(html, 'html.parser')
    print(soup)
else :
    print(res.status_code)

'Web > python' 카테고리의 다른 글

[python](error) is not in list  (0) 2022.03.12
[python] python web crawling 참고 사이트  (0) 2022.03.12