2016-03-25 1 views
0

私は人々の名前と国を抽出するためにウェブサイトを解析しようとしています。以下のようfollow-sibling :: text()とfollowing-sibling :: bの両方を取得するには?

ページは時々になります。私は使用して国を得ることができます

<th>Inventors:</th> 
    <td align="left" width="90%"> 
      <b>Harvey; John Christopher</b> (New York, NY)<b>, Cuddihy; James William</b> (New York, NY) 
    </td> 

//th[contains(text(), "Inventors:")]/following-sibling::td/b[contains(text(),";")]/following-sibling::text() 

[(New York, NY), (New York, NY)] 

時々ページ(国名を中心に追加された)のようになります。

<th>Inventors:</th> 
    <td align="left" width="90%"> 
     <b>Harvey; John Christopher</b> (New York, <b>NY</b>)<b>, Cuddihy; James William</b> (New York, <b>NY</b>) 
    </td> 

I国を得ることができます:

//th[contains(text(), "Inventors:")]/following-sibling::td/b[contains(text(),";")]/following-sibling::b 

[NY, NY] 

今、両方の国で国を取得したいと思います。

//.../following-sibling::text() | //.../following-sibling::b 

が、私はまた、唯一の取得:私も試した

...

//th[contains(text(), "Inventors:")]/following-sibling::td/b[contains(text(),";")]/following-sibling::*[self::text() or self::b] 

が、その後、私は唯一の "B" Sを得る:

は、私が試しました"b" ...

これは期待どおりに機能しないのですか?両方のエントリを取得する任意のソリューションですか?あなたはどちらの場合も

Harvey; John Christopher (New York, NY), Cuddihy; James William (New York, NY) 

を選択しますようにするため

答えて

1

あなたは

string(//th[.="Inventors:")]/following-sibling::td) 

を使用することができます。その後、XPath 2.0文字列/正規表現処理関数を使用するか、XPath 1.0のみが使用可能な場合は、呼び出し言語でそれらの機能を使用します。 「;」を含むBノードを、以下のすべての-兄弟ノードを選択しても無視されます

//th[contains(text(), "Inventors:")] 
    /following-sibling::td/b[contains(text(),";")] 
    /following-sibling::node()[not(self::b[contains(text(),";")])] 

この:

0

また、のような何かをしようとします。

関連する問題