如何使用c#从SELECT标签中提取选项?
问题描述:
我正在写一个简单的C#Windows窗体应用程序,我把它发送到一个网站,并在网站上有一个下拉菜单的选项。我想提取这些选项并将其添加到我自己的应用下拉菜单中。如何使用c#从SELECT标签中提取选项?
到目前为止,我已经写了这样的事情:
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>
谢谢!
答
这似乎这样的伎俩对我来说:
HtmlDocument doc = webBrowser1.Document;
HtmlElementCollection optionValues = doc.GetElementsByTagName("OPTION");
foreach (HtmlElement optTag in optionValues)
{
comboBox1.Items.Add(optTag.InnerText);
}
希望它可以帮助