Reputation: 31
I am using HtmlAgilityPack for scrapping data. Here is the link that i am using to scrap data This Link The structure is something like that
<div id="left">
<h2>
<i id="bn7483" class="fa fa-volume-up fa-lg in au" title="Speak!"/>
<span class="in">(dhaarmika) </span>
<div class="row">
...
I need two data from there one is "(dhaarmika)" and another is the id from that is "bn7483" using this code
HtmlAgilityPack.HtmlDocument doc2 = web2.Load("http://www.shabdkosh.com/bn/translate/ধার্মিক");
HtmlNodeCollection nodes = doc2.DocumentNode.SelectNodes("//span[@class='in']");
I was able to get the first one data that is "(dhaarmika)".
But i couldn't get the second data.
Could anyone tell me how to get the second data???
Upvotes: 0
Views: 254
Reputation: 89285
Another possible way is by selecting preceding sibling of the <span>
you already found :
var doc2 = new HtmlWeb().Load("http://www.shabdkosh.com/bn/translate/ধার্মিক");
var span = doc2.DocumentNode.SelectSingleNode("//span[@class='in']");
var i = node.SelectSingleNode("preceding-sibling::i[@id]")
.Attributes["id"]
.Value;
Upvotes: 1