2024-04-25 06:26:51 发布
网友
我想从降序元素和元素本身中选择文本。什么xpath选择器可以做到这一点?我如何组合所有文本部分?你知道吗
你要找的是//text()。你知道吗
//text()
拍摄于from w3schools:
// - Selects nodes in the document from the current node that match the selection no matter where they are
示例:
$ scrapy shell In [1]: data = """ ...: <div> root text ...: <div> level 2 text </div> ...: <div> level 2 text2 </div> ...: </div> ...: """ In [2]: from scrapy import Selector In [3]: sel = Selector(text=data) In [4]: sel.xpath("//div//text()").extract() Out[4]: [u' root text\n', u' level 2 text ', u'\n', u' level 2 text2 ', u'\n']
你要找的是
//text()
。你知道吗拍摄于from w3schools:
示例:
相关问题 更多 >
编程相关推荐