Reputation: 175
I have to define xpath to access second span text to parse the following name-value html structure (see below) loaded to AgilityPack document. I would to do the folowing query using xpath and C#:
var valueSpan = doc.SelectNodes("//div[@class='container']/div[@class='value2' and ???]/span[2]");
Question: I can't write xpath selector for "second matched div with class=="value2". Is it possible to select second "value2" div using xpath or it should be done by indexing childs of "container" node (actual sibling index of "value2" may vary)?
<div class="container">
<div class="value1">
<span class="name">Title 1</span>
<span class="value">some value</span>
</div>
<div class="value2">
<span class="name">Title 2.1</span>
<span class="value">some value</span>
</div>
<div class="value2">
<span class="name">Title 2.2</span>
<span class="value">some value</span>
</div>
<div class="value3">
<span class="name">Title 3</span>
<span class="value">some value</span>
</div>
</div>
Upvotes: 1
Views: 292