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.