html agility pack - c# htmlagilitypack parse first link from div with class? -
i trying parse first link in html code below /search?id=3
<div class="brs_col"> <p> <a href="/search?id=3"> <b> vastu shastra </b> </a> </p> <p> <a href="/search?id=1"> <b> bygga </b> bastu </a> </p> </div>
i've tried select following xpath, cant seem of them work:
//div[@class='brs_col']//p//a[@href] //div[@class='brs_col']//p[0]//a[@href] //div[@class='brs_col']//p//a[0][@href]
any ideas?
try this:
var doc = new htmldocument(); doc.loadhtml(@"<div class=""brs_col""> <p><a href=""/search?id=3""><b>vastu shastra</b></a></p> <p><a href=""/search?id=1""><b>bygga</b>bastu</a></p> </div>"); var hrefvalue = doc.documentnode .selectsinglenode("//div[@class='brs_col']/p/a") .attributes["href"] .value;
Comments
Post a Comment