2013-03-21 139 views
2

我需要从网站获取表格。为此,我将网页加载到网页浏览器。但除此之外,我需要从下拉菜单中选择所需的选项,然后页面应该更新。然后我将使用html代码。事实证明,我需要更新webbrowser中的数据。我如何实现它? 这就是我试图选择所需的选项:C#在网页浏览器中选择

foreach (HtmlElement element in webBrowser1.Document.All) 
{ 
    if (element.GetAttribute("name") == "Time") 
    { 
     element.Children[6].SetAttribute("selected", "selected"); 
     webBrowser1.Document.GetElementById("Time").InvokeMember("onchange"); 
    }         
} 

但它并没有改变网页浏览器的内容。

编辑:我错过了,那是ajax表。

+0

如果您想要像css选择器一样使用jquery,请使用html敏捷性包和fizzler https://code.google.com/p/fizzler/ – bizzehdee 2013-03-21 22:50:07

+0

如果您尝试抓取数据,请查看HTML敏捷性工具包,它会使使用DOM更简单快捷。 – Matt 2013-03-21 22:58:07

+0

这是在C#还是JS? – 2013-03-22 18:30:00

回答

0

我以前使用以下内容来更改下拉值。它似乎运作良好。

HtmlElement reportDropDown = webBrowser.Document.GetElementById("dropdown_control_id"); 
reportDropDown.Focus(); 
reportDropDown.SetAttribute("value", "Backup Status Report"); //The value of the desired selection 
reportDropDown.InvokeMember("onchange"); 
reportDropDown.RemoveFocus(); 

我创建了一种状态机。这只是一个必须执行的步骤。

+0

有关状态机的任何完整源代码示例? – Kiquenet 2013-12-31 19:06:11