asp.net - How to get the node name of the parent node of an html element using c# -
well need parent node name , respective attributes of html element using c#.
example:
<dl class="dlbox"> <dd> <a class="btn primary" href="http://testurl.org"> <span>lorem ipsum</span> <span class="icnsm"></span> </a> </dd> </dl>
code:
system.windows.forms.htmldocument doc = webbrowser1.document; htmlelementcollection col = doc.getelementsbytagname("a"); int = 0; foreach (htmlelement element in col) { textbox8.text = textbox8.text + col[i].getattribute("id") + "\r\n"; = + 1; }
note: looping through page , searching anchor tags, need check parent element @ 2nd level i.e. exists or not respective anchor tag, if exists need class name respective dl using c#.
thanks! shall appreciated!
well use parent
property, such as:
system.windows.forms.htmldocument doc = webbrowser1.document; htmlelementcollection col = doc.getelementsbytagname("a"); int = 0; foreach (htmlelement element in col) { textbox8.text = textbox8.text + col[i].getattribute("id") + "\r\n"; = + 1; // check if parent dd if(element.parent != null && element.parent.tagname.tolower() == "dd") { var parent = element.parent; if(parent.parent != null && element.parent.tagname.tolower() == "dl") { // class name of dl var classname = parent.parent.getattribute("class"); } } }
Comments
Post a Comment