Php 使用SimpleXML获取;表格「;具有“的元素”;输入“;标签类型为;密码;?
嗨 我有很多表单组成的网页数据(html转换成xml),我想抓取其中有输入标签的表单,类型为password(不需要直接子项)。考虑下面的示例存储在变量$HTML/P>中Php 使用SimpleXML获取;表格「;具有“的元素”;输入“;标签类型为;密码;?,php,html,xml,xpath,simplexml,Php,Html,Xml,Xpath,Simplexml,嗨 我有很多表单组成的网页数据(html转换成xml),我想抓取其中有输入标签的表单,类型为password(不需要直接子项)。考虑下面的示例存储在变量$HTML/P>中 <html> <body> <form> <input type="text" name="foo" /> </form> <form> <table> <tr> <input type="password" name="
<html>
<body>
<form>
<input type="text" name="foo" />
</form>
<form>
<table>
<tr> <input type="password" name="pass"/> </tr>
</table>
</form>
</body>
</html>
但没有成功:(
谢谢。试试这个XPath:
//form[descendant::input[@type="password"]]
另一个选择是
//form//input[@type="password"]/ancestor::form
“//form//input[@type=“password”]”//form,//input用于祖先后代的关系,目标是具有值password的type属性。问题是,在获得password类型的输入元素后,我无法返回到最近的form祖先。
//form//input[@type="password"]/ancestor::form