2017-11-09 7 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-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

私はあなたが望むので、自分で行う必要があります微調整されている正確な形式のわからない:以下のコードを参照してください。

関連する問題