我需要哪些XPath来提取b
中具有特定标签的li
内的文字?
示例代码:
<li>Job category:<b>Engineering</b></li>
<li>Job Type:<b>Full Time</b></li>
示例页面:http://tiruvallur.click.in/job-vacancy-in-uk-needed-engineers-send-your-cv-c98-v15807437
答案 0 :(得分:1)
此XPath表达式
string(//li[starts-with(., 'Job Type:')]/b)
将选择
Full Time
为你的例子。
或者,可能更强大,您可以在li
substring-after(//li[starts-with(., 'Job Type:')], 'Job Type:')
也会选择相同的字符串
Full Time
要消除虚假空白,请使用normalize-space()
:
normalize-space(substring-after(//li[starts-with(., 'Job Type:')], 'Job Type:'))
答案 1 :(得分:0)
试试这个: // * [包含(text(),&#39; your-label-name &#39;)] / b / text( )
例如:
//*[contains(text(),'Job category')]/b/text()