我想获得特定div的属性值,如何做到这一点。
<div id="syllabus-stages" data-featurette="async-element" data-url="/library/aspnet-mvc-forms/stages" data-strategy="update"></div>
答案 0 :(得分:1)
假设您将使用HTML解析器HtmlAgilityPack(您的问题中有标记):
WebClient client = new WebClient();
string downloadString = client.DownloadString("http://www.mywebsite/mypage");
HtmlDocument doc = new HtmlDocument();
doc.LoadHtml(downloadString);
//string whatUrLookingFor = doc.GetElementbyId("syllabus-stages").InnerHtml;
string whatUrLookingFor = doc.GetElementbyId("syllabus-stages").Attributes["data-url"].Value;