2017-05-21 13 views
0

は私が<p lang="title"> Notice how it has <sup></sup> and <sub></sub> tags being used inside.このxpath式で内部HTMLコンテンツを取得するにはどうすればよいですか?

マイXpath式.// Pを抽出しようとしています、上記のHTMLスニペットで一部のHTMLコード

<li><h3>Number Theory - Even Factors</h3> 
    <p lang="title">Number N = 2<sup>6</sup> * 5<sup>5</sup> * 7<sup>6</sup> * 10<sup>7</sup>; how many factors of N are even numbers?</p> 
    <ol class="xyz"> 
     <li>1183</li> 
     <li>1200</li> 
     <li>1050</li> 
     <li>840</li> 
    </ol> 
    <ul class="exp"> 
     <li class="grey fleft"> 
      <span class="qlabs_tooltip_bottom qlabs_tooltip_style_33" style="cursor:pointer;"> 
      <span> 
       <strong>Correct Answer</strong> 
        Choice (A).</br>1183 
       </span> 
       Correct answer 
      </span> 
     </li> 
     <li class="primary fleft"> 
      <a href="factors_6.shtml">Explanatory Answer</a> 
     </li> 
     <li class="grey1 fleft">Factors - Even numbers</li> 
     <li class="orange flrt">Medium</li> 
    </ul>  
</li> 

を持っている/テキスト[LANG = "タイトル" @]() subとsupの内容を取得しません。それという

//p[@lang="title"]/node() 

注:どのように私は、XPath

下に所望の出力

Number N = 2<sup>6</sup>*5<sup>5</sup> * 7<sup>6</sup> * 10<sup>7</sup>; how many factors of N are even numbers? 
+0

クエリ? –

+0

こちらを参照してください。https://stackoverflow.com/questions/11744465/xpath-difference-between-node-and-text –

答えて

0

この出力を得るのですか

あなたは、単に以下のようにnode()innerHTMLを得ることができます配列を返すノード

のPython

あなたはPythonコード

from BeautifulSoup import BeautifulSoup 

def innerHTML(element): 
    "Function that receives element and returns its innerHTML" 
    return element.decode_contents(formatter="html") 

html = """<html> 
       <head>... 
       <body>... 
       Your HTML source code 
       ...""" 

soup = BeautifulSoup(html) 
paragraph = soup.find('p', { "lang" : "title" }) 

print(innerHTML(paragraph)) 

以下の出力でinnerHTMLを必要得ることができます:あなたがHTMLを解析し、XPathを実行するために使用している言語

'Number N = 2<sup>6</sup> * 5<sup>5</sup> * 7<sup>6</sup> * 10<sup>7</sup>; how many factors of N are even numbers?' 
関連する問題