首页 > 解决方案 > 带有标记的文本的 XPath 字符串连接

问题描述

我的 HTML 代码如下所示:

<td>Known text and something <i>follows</i> or not</td>
<td>Unknown text <b>with some</b> subcontainer(s) or without it</td>

让我们说:

<td>Address line 1 <i>(office)</i> in <b>Dallas</b></td>
<td>1, Main Ave. <b>Dallas</b>, 123456</td>

在上面的示例中,“地址行”是已知文本,“1”可能跟在后面,也可能不在,也可能是“2”或“3”等,并且在任何位置都包含 HTML 标记,甚至在已知文本。“1, Main Ave. Dallas, 123456” 是未知文本,可能在任何地方包含一些超文本标记,也可能不包含。

因此,我需要捕获整个字符串“1, Main Ave. Dallas, 123456”,并为 Screaming Frog SEO Spider 编写以下 XPath 表达式:

//td[starts-with(descendant-or-self::*/text(),'Address line')][1]/following-sibling::*[1]//descendant-or-self::*/text()

除了将输出加入一行之外,它成功地完成了它的工作。猜猜我需要使用字符串连接函数,但是当我是 XPath 的新手时,语法失败了。有人可以帮忙吗?

标签: htmlparsingxpath

解决方案


推荐阅读