目前我已经获得了我想要的节点的示例xpath:
/html
/body
/div[@id='wp']
/div[@id='ct']
/div
/div[@id='threadlist']
/div[2]
/form
/table
/tbody[@id='normalthread_1174131']
/tr
/th
/a
我不需要的东西:
/html
/body
/div[@id='wp']
/div[@id='ct']
/div
/div[@id='threadlist']
/div[2]
/form
/table
/tbody[@id='stickthread_1174132']
/tr
/th
/a
当然,我可以使用以下方式选择它们:
/html/body/div[@id='wp']/div[@id='ct']/div/div[@id='threadlist']
/div[2]/form/table/tbody[@id]/tr/th/a
但我只想选择id为normalthread_xxx的节点。由于每个节点具有不同的id。换句话说,目标页面可能包含以下节点:
/html/body/div[@id='wp']
/div[@id='ct']
/div/div[@id='threadlist']
/div[2]/form/table/tbody[@id='normalthread_1174133']
/tr/th/a
/html/body/div[@id='wp']
/div[@id='ct']
/div/div[@id='threadlist']
/div[2]/form/table/tbody[@id='normalthread_1174134']
/tr/th/a
我们能否有类似
的内容/html/body/div[@id='wp']
/div[@id='ct']
/div/div[@id='threadlist']
/div[2]/form/table/tbody[@id='normalthread_XXX']
/tr/th/a
,为了过滤这里的所有节点?
答案 0 :(得分:2)
您应该能够使用starts-with()
(XPath 1.0的一部分):
/html/body/(...)/form/table/tbody[starts-with(@id,'normalthread_')]/tr/th/a