c#如何从内部抓住绳子<;b>;那';它在一个div类中
所以我一直在使用这样的东西:c#如何从内部抓住绳子<;b>;那';它在一个div类中,c#,C#,所以我一直在使用这样的东西: webBrowser1.Document.GetElementById("month").SetAttribute("value", exp1); 这允许我设置值,但现在我想获取一个值,而不是替换它 <div class="contents"> <div class="background">stuff</div> <div class="content"> <h2>title</h2> &l
webBrowser1.Document.GetElementById("month").SetAttribute("value", exp1);
这允许我设置值,但现在我想获取一个值,而不是替换它
<div class="contents">
<div class="background">stuff</div>
<div class="content">
<h2>title</h2>
<p>
Blah blah number is <b>0100000</b>
<p>
</div>
</div>
东西
标题
这个号码是0100000
如何获取内容类中的标记内的数字?有点卡住了
谢谢 您始终可以获取所选标记的
InnerText
或InnerHtml
。
尝试以下答案:如中所述
这是您需要的代码:
string theText;
foreach (HtmlElement item in webBrowser1.Document.GetElementsByTagName("div"))
{
if (item.GetAttribute("className") == "content")
theText = item.GetElementsByTagName("b")[0].InnerText;
}
webBrowser1.Document.GetElementById(“month”).val()@idipous我想他想要元素中的值,而不是month容器中的整个值。我希望从类中获取值,而不是从和ID。我尝试了问题中的值,但没有成功。你说你不知道如何获取标记的内容。这是你问题的正确答案。但事实证明,您也不知道如何获得
标记。为此,您需要GetElementsByTagName(“b”)[0]
webBrowser1.Document.GetElementsByTagName(“div”).Cast()。其中(p=>p.GetAttribute(“className”)==“content”).First().GetElementsByTagName(“b”)[0]。InnerText@VaughanSlaterit不,它适用于您在问题中提供的html抱歉,我在html中遗漏了一些东西(因为我很愚蠢)。我用完整的html更新了这个问题。。这就是它不适合我的原因吗?很抱歉
string theText;
foreach (HtmlElement item in webBrowser1.Document.GetElementsByTagName("div"))
{
if (item.GetAttribute("className") == "content")
theText = item.GetElementsByTagName("b")[0].InnerText;
}