擅长:python、mysql、java
<p>经过一番反复,我们发现需要一个名称空间才能正常工作。xpath方法是合适的解决方案,它只需要首先传递文档命名空间。</p>
<p><a href="http://lxml.de/xpathxslt.html#the-xpath-method" rel="nofollow">lxml xpath method</a>包含命名空间内容的详细信息。查看链接中的页面以获取传递名称空间字典和其他详细信息的信息。</p>
<p>正如mgierdal在其上述评论中所解释的:</p>
<blockquote>
<p>tblList = document.xpath('//w:tbl', namespaces=document.nsmap) works
like a dream. So, as I understand it w: is a shorthand that has to be
expanded to the full namespace name, and the dictionary for that is
provided by document.nsmap.</p>
</blockquote>