【发布时间】:2014-11-26 14:45:34
【问题描述】:
我有 HTML 代码,我想用 xPath 解析以“倒入所有成分”开头的字符串。我已经用 span 和 li 对象完成了这个技巧。但是这个文本不属于任何东西。 xpath应该怎么写?
李的EG:
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> </p>
</div>
</div>
【问题讨论】: