2016-06-16 11 views
2

ここに状況があります。私は別のドメインからのHTMLページからいくつかの情報を取得する必要があります。一つのドメインで、私は必要な情報は次のようになります。他にユニバーサルxpathクエリ

<div class='class1'> 
    <span class='class2'> TEXT I NEED </span> 
</div> 

またがるなしがあるタグ:両方のケースのためのテキストを取得する代わりのための普遍的なXPathクエリが

<div class='class1'> TEXT I NEED </div> 

ありますを使用している場合ステートメント?

ここで私はこれまで得たものです:

提供だけでHTMLを考える
if domain == 'com': 
    rating = x.xpath('//span[@class="class2"]/text()') 
if domain == 'de': 
    rating = x.xpath('//div[@class="class1"]/text()') 
+0

を...つまり '文字列(// divの[@classに= class1 "])'または 'normalize-space(// div [@ class =" class1 "])' – Phil

答えて

2

//*[contains(@class,'class1')]/descendant::text() 

enter image description here