Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html xpath,函数通过搜索元素来标识类?_Html_Xpath - Fatal编程技术网

Html xpath,函数通过搜索元素来标识类?

Html xpath,函数通过搜索元素来标识类?,html,xpath,Html,Xpath,我是xpath和html的新手。是否可以在html中搜索每个类“authorbox”下的文本“xxxx”,如果该类中有文本,则自动选择父类tr xxxx 桌子上还有更多的东西 编辑 这是我目前能够创建的xpath //td[@class='authorbox'] 我真的不知道如何搜索文本“xxxx”,或者如果找到文本,如何选择父tr。如果我想的话,我可以选择每个表,但是如果它更自动化,那就更好了 谢谢使用: //tr[td[@class='authorbox']

我是xpath和html的新手。是否可以在html中搜索每个类“authorbox”下的文本“xxxx”,如果该类中有文本,则自动选择父类tr

桌子上还有更多的东西

编辑 这是我目前能够创建的xpath

//td[@class='authorbox']

我真的不知道如何搜索文本“xxxx”,或者如果找到文本,如何选择父tr。如果我想的话,我可以选择每个表,但是如果它更自动化,那就更好了

谢谢

使用

//tr[td[@class='authorbox']
           //text()[contains(., 'xxxx')]
    ]
//tr[td[@class='authorbox']
           //text()[. = 'xxxx']
    ]
//tr[td[@class='authorbox']
           //text()[starts-with(., 'xxxx')]
    ]
//tr[td[@class='authorbox']
           //text()[normalize-space(., 'xxxx')]
    ]
这将选择XML文档中具有
td
子级且其
class
属性的字符串值为字符串
“authorbox”
的任何
tr
,并且(该
td
子级)具有文本节点后代,其字符串值为包含
“xxxx”
的字符串

这可能会更精确:

如果文本节点子体的字符串值必须正好是字符串
“xxxx”
,则使用

//tr[td[@class='authorbox']
           //text()[contains(., 'xxxx')]
    ]
//tr[td[@class='authorbox']
           //text()[. = 'xxxx']
    ]
//tr[td[@class='authorbox']
           //text()[starts-with(., 'xxxx')]
    ]
//tr[td[@class='authorbox']
           //text()[normalize-space(., 'xxxx')]
    ]
如果文本节点子体的字符串值应以字符串
“xxxx”
开头,请使用

//tr[td[@class='authorbox']
           //text()[contains(., 'xxxx')]
    ]
//tr[td[@class='authorbox']
           //text()[. = 'xxxx']
    ]
//tr[td[@class='authorbox']
           //text()[starts-with(., 'xxxx')]
    ]
//tr[td[@class='authorbox']
           //text()[normalize-space(., 'xxxx')]
    ]
如果文本节点子体的字符串值应包含仅由空白包围的字符串
“xxxx”
,请使用

//tr[td[@class='authorbox']
           //text()[contains(., 'xxxx')]
    ]
//tr[td[@class='authorbox']
           //text()[. = 'xxxx']
    ]
//tr[td[@class='authorbox']
           //text()[starts-with(., 'xxxx')]
    ]
//tr[td[@class='authorbox']
           //text()[normalize-space(., 'xxxx')]
    ]

看来你已经走到一半了。您只需要在谓词中添加一点牛肉:

//tr[td/@class="authorbox" and td/div/a="xxxx"]

另外,如果您想要
tr
,可以从上面开始,并将
td
引用向下推到谓词中。

您是否可以展示创建xpath的任何尝试?这将是一个有用的起点,了解你的困境。嗨。谢谢这是我目前能够使用的xpath//td[@class='authorbox']我真的不知道如何搜索文本“xxxx”或在找到文本时选择父tr。如果我愿意,我可以选择每个表,但如果它更自动,那就更好了。那么,对于提供的XML,您希望被选择/检索的具体情况是什么?谢谢你们,你们都是天使。@TokDoom:不客气。至于天使,好吧,你们刚刚意识到XPath就是天堂:)谢谢你们,你们都是天使。