如何使用c#从SELECT标记中提取OPTIONS?

时间:2010-11-29 06:42:15

标签: c# asp.net html

我正在编写一个简单的C#Windows窗体应用程序,我将其发送到网站,并在网站上有一个带有选项的下拉菜单。我想提取这些选项并将其添加到我自己的应用程序的下拉菜单中。

到目前为止,我写过这样的话:

HtmlElementCollection optionValues = curElement.GetElementsByTagName("OPTION");
foreach (HtmlElement curOptions in optionValues)
{
    string options = curOptions.InnerText.ToString();
    // store into an array
   foreach (string i in stringArray)
       combobox1.Items.Add(i)
}

HTML是这样的:

<select id="some_values">
    <option value="O">Barack Obama</option>
    <option value="G">George Bush</option>
</select>

谢谢!

1 个答案:

答案 0 :(得分:1)

这似乎对我有用:

HtmlDocument doc = webBrowser1.Document;
HtmlElementCollection optionValues = doc.GetElementsByTagName("OPTION");
foreach (HtmlElement optTag in optionValues)
{
    comboBox1.Items.Add(optTag.InnerText);
}

希望有所帮助

相关问题