简体   繁体   中英

How To Get Href Link Using Xpath C#?

<a href="/buffet-lau--nuong-hon-200-mon-an-huong-vi-han-quoc-tai-seoul-garden-hien-dai-nhat-vn-170ecccd214b42f8/dat-mua" id="cmPurchaseLink" name="cmPurchaseLink"></a>

how to get

"/buffet-lau--nuong-hon-200-mon-an-huong-vi-han-quoc-tai-seoul-garden-hien-dai-nhat-vn-170ecccd214b42f8/dat-mua" id="cmPurchaseLink" name="cmPurchaseLink"

using xpath (C#)?

Assuming the XML markup you posted resides in an XmlDocument , you can write:

string href
    = yourXmlDoc.SelectSingleNode("//a[@id='cmPurchaseLink']/@href").Value;

使用HtmlAgilityPack ,我会用这个:

string summary = doc.DocumentNode.SelectNodes("//a[@id='cmPurchaseLink']")[0].Attributes["href"].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