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