BeautifulSoup를 이용한 웹 데이터 스크래핑

매일 공부(ML)·2022년 2월 24일
0

BeautifulSoup을 활용한 웹 스크래핑

BeautifulSoup는 아주 강력한 라이브러리로 urllib과 더불어 사용하면 다음과 같이 원하는 웹 페이지에 존재하는 모든 링크의 URL을 출력할 수 있습니다.

왜냐하면, 이것은 웹페이지에서 일어날 수 있는 다양한 문제들에 대해서 해결책을 모아놓은 것입니다.

import urllib.request, urllib.parse, urllib.error
from bs4 import BeautifulSoup

url = input('Enter - ') #https://pypi.python.org/pypi/beautifulsoup4
html = urllib.request.urlopen(url).read()
soup = BeautifulSoup(html, 'html.parser')

# Retrieve all of the anchor tags
tags = soup('a')
for tag in tags:
    print(tag.get('href', None))
profile
성장을 도울 아카이빙 블로그

0개의 댓글