简体   繁体   中英

How to get specific data using HtmlAgilityPack

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???

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM