2017-11-09 3 views
-1
<div class=" col-md-8"> 
    <strong>3.</strong>&nbsp;&nbsp;&nbsp;&nbsp;For 
    <i>ax</i> 
    <sup>2</sup> + <i>bx</i> + <i>c</i> = 0, 
    which of the following statement is wrong? 
</div> 
<div class="row"> 
    <div class=" col-md-6"> 
    (a) three zeros 
    </div> 
    <div class=" col-md-6"> 
    (b) one zero 
    </div> 
    <div class=" col-md-6"> 
    (c) two zeros 
    </div> 
    <div class=" col-md-6"> 
    (d) none of these 
    </div> 
</div> 

위의 코드는 모든 질문과 대답에 대해 반복됩니다. BeautifulSoup을 사용하여 데이터를 검색하지만 성공하지 못했습니다.HTML 태그에서 텍스트를 가져 오는 방법은 무엇입니까?

BeautifulSoup를 사용하여 데이터를 검색하는 방법 (텍스트 및 HTML 태그 없음)을 알려줄 수있는 사람이 있습니까?

+1

가능한 복제본 https://stackoverflow.com/questions/16206380/python-beautifulsoup-how-to-remove-all-all-tags-from-an-element? – Polymer

+0

제공된 링크가 내 문제의 올바른 해결책이 아닙니다. – john

+0

예제 솔루션을 제공해 주시겠습니까? – Polymer

답변

1

** 참고, 내가 지정한 것을 포함하는 마크 업을 편집 **

난 그냥 몇 가지 코드를 컴파일하고 나는 이것이 올바른 문자열을 출력하는 것을 확인할 수 있습니다. 아래의 코드를 참조하십시오 :

from bs4 import BeautifulSoup 

string = """<div class=" col-md-8"> 
<strong></strong>Every quadratic polynomial can have at most 
</div> 
<div class="row"> 
<div class=" col-md-6"> 
(a) three zeros 
</div> 
<div class=" col-md-6"> 
(b) one zero 
</div> 
<div class=" col-md-6"> 
(c) two zeros 
</div> 
<div class=" col-md-6"> 
(d) none of these 
</div> 
</div>""" 

soup = BeautifulSoup(string, "html.parser") 
text = soup.get_text().replace("\n", "") 

print(text) 

을이 뜻 난 그렇게 자신이 수행해야합니다 조정, 당신이 원하는되는 정확한 형식의 확실하지 않다 출력

Every quadratic polynomial can have at most (a) three zeros(b) one zero(c) two zeros(d) none of these

.

관련 문제