1
A
答えて
2
あなたが翻訳者からの著者を区別するためにtranslation:
テキストノードことを使用することができます - 作者はあります"translation:"テキストノードの先行する兄弟、翻訳者 - 兄弟の後ろ。
著者:
//text()[contains(., 'translation:')]/preceding-sibling::a[@class='booklink' and contains(@href, '/author/')]/text()
翻訳者:
//text()[contains(., 'translation:')]/following-sibling::a[@class='booklink' and contains(@href, '/author/')]/text()
作業サンプルコード:
from lxml.html import fromstring
data = """
<td>
<a class="booklink" href="/author/43710/Author 1">Author 1</a>
,
<a class="booklink" href="/author/46907/Author 2">Author 2</a>
<br>
translation:
<a class="booklink" href="/author/47669/translator 1">Translator 1</a>
,
<a class="booklink" href="/author/9382/translator 2">Translator 2</a>
</td>"""
root = fromstring(data)
authors = root.xpath("//text()[contains(., 'translation:')]/preceding-sibling::a[@class='booklink' and contains(@href, '/author/')]/text()")
translators = root.xpath("//text()[contains(., 'translation:')]/following-sibling::a[@class='booklink' and contains(@href, '/author/')]/text()")
print(authors)
print(translators)
プリント:
関連する問題
- 1. Pythonを使用してウェブページから特定のテキストを選択
- 2. コンボボックスwinformで特定のテキストを選択した場合
- 3. 特定のテーブルを選択
- 4. xpath式 - 親が特定のテキストを含む要素を選択
- 5. メモ帳++テキスト内の特定の領域を選択する
- 6. PDFNetの特定のページで(テキスト)選択を取得する
- 7. XPathでテキストブロック内の特定のテキストを選択する
- 8. jQueryでテキスト入力ボックス内の特定の場所を選択
- 9. VBAでWordの特定の列からテキストを選択
- 10. 特定のテキストを選択するにはスクロールでTextAreaで
- 11. 特定年のパンダ選択
- 12. のXPath:特定のタグの後のテキストを選択し、同じ次のタグ
- 13. jsonの文字列から特定のテキストを選択してください
- 14. 特定の選択の子ではない要素を選択
- 15. 生成選択で特定の列を選択する
- 16. 選択メニューから特定の行を選択する - PHP/Mysql
- 17. jQueryは、選択肢で「選択」された特定の選択肢を選択します。
- 18. Ionic 2の特定のタブを選択
- 19. グラフ上の特定の値を選択
- 20. SFrameの特定の行を選択
- 21. UIScrollviewで特定の画像を選択
- 22. Redis sentinel failover、特定のマスタを選択
- 23. Python、特定の行を選択
- 24. ComboBox特定のオブジェクトIDを選択
- 25. jquery特定の子を選択
- 26. 特定の時間を選択
- 27. Gridviewで特定の行を選択
- 28. mongorc.jsで特定のデータベースを選択
- 29. OpenXML特定の列を選択する
- 30. clangで特定のlibstdC++バージョンを選択