# BeautifulSoup으로 XML 문서 처리
import urllib.request as req
from bs4 import BeautifulSoup
url = "https://raw.githubusercontent.com/pykwon/python/master/seoullibtime5.xml"
plainText = req.urlopen(url).read().decode()
# print(plainText)
soup = BeautifulSoup(plainText, 'lxml') # html.parser
libData = soup.select('row')
for data in libData:
name = data.find('lbrry_name').text # 대문자로 안 나오면 소문자로 해 보기
addr = data.find('adres').text
print('도서관명 :', name)
print('주 소 :', addr)
<console>
C:\anaconda3\lib\site-packages\bs4\builder\__init__.py:545: XMLParsedAsHTMLWarning: It looks like you're parsing an XML document using an HTML parser. If this really is an HTML document (maybe it's XHTML?), you can ignore or filter this warning. If it's XML, you should know that using an XML parser will be more reliable. To parse this document as XML, make sure you have the lxml package installed, and pass the keyword argument `features="xml"` into the BeautifulSoup constructor.
warnings.warn(
도서관명 : LH강남3단지작은도서관
주 소 : 서울특별시 강남구 자곡로3길 22
도서관명 : 강남구립못골도서관
주 소 : 서울특별시 강남구 자곡로 116
도서관명 : 강남역삼푸른솔도서관
주 소 : 서울특별시 강남구 테헤란로8길 36. 4층
도서관명 : 강남한신휴플러스8단지작은도서관
주 소 : 서울특별시 강남구 밤고개로27길 20(율현동, 강남한신휴플러스8단지)
도서관명 : 강남한양수자인작은씨앗도서관
주 소 : 서울특별시 강남구 자곡로 260