擅长:python、mysql、java
<p>XPath允许<code>$variables</code>,lxml的<code>.xpath()</code>方法允许将这些变量的值作为关键字参数提供:<code>.xpath('$variable', variable='my value')</code></p>
<p>以你的例子,你可以这样做:</p>
<pre><code>fonds_name = 'Imtech'
aandeel = tree.xpath('//a[@title="$title"]/text()', title=fonds_name)
print(aandeel)
</code></pre>
<p>更多信息请参见lmxl的文档:<a href="http://lxml.de/xpathxslt.html#the-xpath-method" rel="noreferrer">http://lxml.de/xpathxslt.html#the-xpath-method</a></p>