실행 전 BeautifulSoap4 (BS4) 라이브러리 설치해야함
[소스코드]
from urllib.request import urlopen url = "https://www.naver.com"html = urlopen(url) #print(html.read()) import bs4 html_str = "<html><div> hello </div></html>"bs_obj = bs4.BeautifulSoup(html_str, "html.parser") print(type(bs_obj)) print(bs_obj) print(bs_obj.find("div")) html_str4 = """<html> <body> <ul> <li>hello</li> <li>bye</li> <li>welcome</li> </ul> </body></html>""" bs_obj4 = bs4.BeautifulSoup(html_str4, "html.parser") ul = bs_obj4.find("ul") print(ul) li = bs_obj4.find("li") print(li) print(li.text) lis = bs_obj4.findAll("li") print(lis) print(lis[1].text) [결과]
<class 'bs4.BeautifulSoup'>
<html><div> hello </div></html>
<div> hello </div>
<ul>
<li>hello</li>
<li>bye</li>
<li>welcome</li>
</ul>
<li>hello</li>
hello
[<li>hello</li>, <li>bye</li>, <li>welcome</li>]
bye
웹 크롤링 파이썬 1
Reviewed by kukanuc
on
2월 18, 2019
Rating:
Power Supply Titanium - Titanium Arts
답글삭제The manufacturer titanium wedding band of titanium band ring high quality power smith titanium supplies. Power supplies include titanium drill bits for metal all standard equipment such as batteries and power-cycle batteries titanium fat bike and Material: Synthetic, stainless steel