[英]Python: What's wrong with my xpath expression?
I have this:我有这个:
<div class="down_butt_pad1" style="" id="downloadlink"><a href="http://www.link.com" class="down_butt1" onclick="javascript:window.open('http://s.spam.com','popunder','width=800,height=800,scrollbars=yes,status=no,resizable=yes, toolbar=no'); window.focus();"></a></div>
I'm trying to do a xpath("//div[@id == 'downloadlink']")
but I get an error ("lxml.etree.XPathEvalError: Invalid expression").我正在尝试执行
xpath("//div[@id == 'downloadlink']")
但出现错误(“lxml.etree.XPathEvalError: Invalid expression”)。
What's wrong with what I am doing and how can I search for a div with the id that has downloadlink instead then?我在做什么有什么问题,我该如何搜索具有下载链接的 id 的 div 呢?
You have to use a single =
in XPath.您必须在 XPath 中使用单个
=
。 What you're looking for is你正在寻找的是
"//div[@id='downloadlink']"
However , there is nothing interesting about the div.但是,div 没有什么有趣的地方。 Why stop there?
为什么停在那里? Perhaps you want to extract the URL:
也许您想提取 URL:
"//div[@id='downloadlink']/a/@href"
I recommend using a deep dive to extract exactly what you want, rather than stopping at a container element, then invoking the xpath engine again or switching to tree-style navigation.我建议使用深入挖掘来准确提取您想要的内容,而不是在容器元素处停止,然后再次调用 xpath 引擎或切换到树形导航。
I should be我应该
"//div[@id='downloadlink']"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.