응용 프로그램과 같은 작은 브라우저를 만드는 동안
Strip html from strings in python
내가 파이썬에서 그렇게 할 수있는 방법 : 문자열
<html> <h1> good morning </h1> welcome </html>
나는 다음과 같은 출력을 필요로 생각해?
응용 프로그램과 같은 작은 브라우저를 만드는 동안
Strip html from strings in python
내가 파이썬에서 그렇게 할 수있는 방법 : 문자열
<html> <h1> good morning </h1> welcome </html>
나는 다음과 같은 출력을 필요로 생각해?
pythons html/xml 파서 중 하나를 사용할 수 있습니다.
아름다운 스프가 인기입니다. lmxl도 인기가 있습니다.
def get_text(etree):
for child in etree:
if child.text:
yield child.text
if child.tail:
yield child.tail
import xml.etree.ElementTree as ET
root = ET.fromstring('<html> <h1> good morning </h1> welcome </html>')
print list(get_text(root))
내가 xml.etree.ElementTree
를 사용하는 것이 표준 라이브러리를 사용할 수 있습니다 타사 pacakges 있습니다. 도움말과 관련된 몇 줄의 내용입니다.
from bs4 import BeautifulSoup
soup = BeautifulSoup('<html> <h1> good morning </h1> welcome </html>')
print [text for text in soup.stripped_strings]
나는 당신의 목표를 달성하기 위해 파이썬 라이브러리 Beautiful Soup
을 사용 :
위
는 너무