Programing/Scripts
[python] BeautifulSoup 로 XML 처리하기
나모찾기
2020. 2. 18. 12:57
엄밀히 이야기 하면 XML은 아니나 마크업 문서를 처리하기 위함이다.
from bs4 import BeautifulSoup
with open("user.xml") as fp:
soup = BeautifulSoup(fp, 'html.parser')
body = soup.grid.body.b
for ele in body.find_all("i"):
print ele["name"].encode('utf8')
처리하다 발견한 예외
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
관련내용: https://ourcstory.tistory.com/39
처리방법:
.encode('utf8')