Skip to content

Web Pages

InYeop Lee edited this page Mar 11, 2016 · 1 revision

BeautifulSoup은 웹 스크랩을 하기 위한 파이썬 라이브러리입니다.

다음은 기본적은 예제입니다.

from bs4 import BeautifulSoup
import urllib

r = urllib.urlopen('http url').read()
b = BeautifulSoup(r)
tds = b.find_all(태그 이름,클래스 이름)
for td in tds:
    a = td.find('a')#td안에 있는 a태그에 접근
    a['href'] #a태그의 href 어트리뷰트에 접근
    td.text #td 태그 안에 있는 텍스트

BeautifulSoup 클래스에 html문서를 넘겨주면 손쉽게 각종 태그에 접근할 수 있습니다. find, find_all의 함수로 원하는 태그를 클래스와 아이디별로 받아올 수 있습니다. 또한 태그의 부모,자식간의 관계도 파악하고 있기 때문에 자유롭게 이동 가능합니다.

이 라이브러리를 이용하여

http://djhpoem.co.kr - 소스

http://essay.or.kr - 소스

http://www.essayistclub.or.kr - 소스

http://www.qtessay.or.kr - 소스

http://www.supil.or.kr - 소스

에서 데이터를 모았습니다.

#HOME

###SCRAPING

###Text

  • Konlpy

###Document Classification

###Result

###APOLOGY

Clone this wiki locally