0
인터넷을 검색했는데 특정 태그와 그 내용 외의 모든 것을 제외시킬 수있는 항목을 찾을 수 없습니다.특정 html 태그와 그 내용을 제외한 모든 것을 파이썬에서 제거합니다.
어떻게 이것을 파이썬 (beautifulsoup 4)으로 할 수 있습니까?
<iframe width="1000" height="500" allowfullscreen="allowfullscreen" class="embed" src="#"> </iframe>
나 ':
<p><iframe width="1000" height="500" allowfullscreen="allowfullscreen" class="embed" src="#"> </iframe></p>
<p>sdkjasdkljasldjad;j dadas dasdadada</p>
내가 그렇게 출력은 다음과 같이 다른 모든를 제거해야합니다
나는이 HTML을 와라. 그러나이 최대가 더 이상 갈 방법을 알고하지 않습니다
@register.filter(name='only_iframe')
def only_iframe(content):
soup = BeautifulSoup(content)
for tag in soup.find_all('p', 'strong'):
tag.replaceWith('')
return soup.get_text()
어쩌면 정규식이 도움이 될 것입니다, 단지 아이디어를 – Robinlemon