如何在<p>之间使用xPath获取文本?</p>

时间:2014-10-01 17:12:41

标签: python html xpath lxml

我有HTML代码,我想解析以&#34开头的字符串;倒入所有成分&#34;使用xPath。我已经完成了span和li对象的技巧。但是这个文本并不属于任何东西。我该怎么写xpath?

EG for li:

for ingredients in doc.xpath("//div[@class='oc_info']/ul[@class='list']/li"):
    print ingredients.text

这是HTML:

<div class="oc_info" style="float: left; width: 400px; color: #666666; font-size: 12px; line-height:     16px;">
<p class="info"><span class="info1" style="color:#818915; font-size:16px; font-weight:bold;">CASINO</span> <br><span class="info2" style="color:black; font-size:12px; font-weight:bold;">All Day Cocktail</span></p>
<ul class="list">
<li>4 cl Old Tom Gin</li>
<li>1 cl Maraschino</li>
<li>1 cl Orange Bitters</li>
<li>1 cl Fresh lemon juice</li>
</ul>
Pour all ingredients into shaker with ice cubes, shake well, strain into chilled cocktail glass and     garnish with a lemon twist and a maraschino cherry.
<p>&nbsp;</p>
</div>
</div>

1 个答案:

答案 0 :(得分:1)

您可以选择&#34;倒入所有成分......&#34;直接使用此XPath发送文本:

//div[@class='oc_info']/ul[@class='list']/following-sibling::text()
相关问题