本文介绍了如何阅读子元素“strong”跨度? C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 大家好, 我正在尝试阅读跨度的子元素强。我希望然后把它转换为字符串。 所以在这种情况下我试图读取强值,即4号。 br /> 有没有人有任何想法我怎么能做到这一点。 这是一份HTML的副本网页供参考。 Imgur:互联网上最棒的图片 [ ^ ] 提前谢谢 我的尝试: 我已经尝试过在各种论坛上观看,包括这个,没有运气。 我目前为止代码 Hi Guys,I'm trying to read the child element "Strong" of a span. I'm looking to then convert it to a string.so in this case I'm trying to read the "strong" value which is the number 4.Does anyone have any ideas how i can achieve this please.Here is a copy of the HTML web page for reference.Imgur: The most awesome images on the Internet[^]Thank you in advanceWhat I have tried:I have already tried looking on various forums including this one and no luck.Code i have so far HtmlElementCollection allelements = _webBrowser.Document.All; foreach (HtmlElement webpageelement in allelements) { if ((webpageelement.GetAttribute("span") == "4")) { MessageBox.Show("Show"); }} 自从学到目前为止所说的这个帖子我有这个。 since learning from what is said so far in this thread i have this.HtmlElementCollection theElementCollection = default(HtmlElementCollection);theElementCollection = webBrowser1.Document.GetElementsByTagName("div");foreach (HtmlElement curElement in theElementCollection){ if (curElement.GetAttribute("className").ToString() == "ng-scope") { HtmlElementCollection childDivs = curElement.Children.GetElementsByName("strong"); foreach (HtmlElement childElement in childDivs) { MessageBox.Show(childElement.InnerText); } }} 推荐答案 HtmlElementCollection theElementCollection = default(HtmlElementCollection);// you need a list of the "span" elements, not "div"theElementCollection = _webBrowser.Document.GetElementsByTagName("span");foreach (HtmlElement curElement in theElementCollection){ if (curElement.GetAttribute("className").ToString() == "ng-scope") { // there isn't a GetElementsByTagName (GetElementsByName is something else) on the child element so we'll // iterate through all children.... HtmlElementCollection childDivs = curElement.Children; foreach (HtmlElement childElement in childDivs) { // ..and check the TagName for "strong" if (string.Compare(childElement.TagName, "strong", true) == 0) { MessageBox.Show(childElement.InnerText); } } }} 这篇关于如何阅读子元素“strong”跨度? C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-22 19:26