dev
python BeautifulSoup
지렁이의야망
2017. 2. 25. 01:45
이런 것이 있다.
https://www.crummy.com/software/BeautifulSoup/
파이선에서 사용하는 라이브러리인데,
jquery 쓰듯 html 문서를 탐색하고 엘리먼트를 조회하고 속성값을 얻을 수 있다.
조금 써봤는데 짱인 듯.
설치 방법부터 사용 방법까지 정리해둔 블로그 워낙 많으니 다 할 필요는 없고..
초간략..
from bs4 import BeautifulSoup
html = "<html>....<div class='ccc'>...</div>...<p id='hoho'>...</p>...</html>"
soup = BeautifulSoup(responses, "html.parser")
content = soup.find("div") # div 요소를 찾는다.
content = soup.find(id="hoho") # id가 hoho 인 요소를 찾는다.
content = soup.find("div", class_="ccc") # div 요소 중 ccc 클래스를 달고 있는 걸 찾는다.
arraylist = soup.find_all("div") # div 요소를 모두 찾아 배열로 반환한다.
써보면 안다.
이게 얼마나 짱인지. ㅎ