Lxml html xpath context

匿名 (未验证) 提交于 2019-12-03 02:56:01

问题:

I'm using lxml to parse a HTML file and I'd like to know how can I set the context of xpath search. What I mean I that I have a node element and want to make xpath search only inside this node as if it was the root one. For example, I have a form node and xpath search //input return only inputs of the given form as opposed to all inputs of all forms on the page. How can I do that? I've found some xpath context docs here, but it doesn't seems to be quite what I want.

回答1:

XPath expression //input will match all input elements, anywhere in your document, while .//input will match all inside current context.

Maybe if you improve your scenario description we can help you further.



转载请标明出处:Lxml html xpath context
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!