2

I have the HTML code and I want to parse string that starts with "Pour all ingredients" with xPath. I have already done the trick with span and li objects. But this text is not belonged to anything. How should I write the xpath?

EG for li:

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

This is the 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>
M. A. Kishawy
  • 5,001
  • 11
  • 47
  • 72
alex
  • 31
  • 7

1 Answers1

1

You can select the "Pour all ingredients..." text directly with this XPath:

//div[@class='oc_info']/ul[@class='list']/following-sibling::text()
kjhughes
  • 106,133
  • 27
  • 181
  • 240