0

提前致谢..

如何在 for 循环中的每个元素单击语句后重新加载我的 Web 浏览器???

case "Assessment     Database - Initial Search Results":

objHtmlDoc = (System.Windows.Forms.HtmlDocument)webBrowser1.Document;
HtmlElementCollection row3 = (HtmlElementCollection)objHtmlDoc.GetElementsByTagName("input");
foreach (HtmlElement element in row3)
{
    if (element.GetAttribute("type").ToString() == "submit" && element.GetAttribute("name").ToString() == "View")
    {
        element.Focus();
        element.RaiseEvent("onclick");
        //webBrowser1.GoForward();
       // webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
    }
}
break;
4

1 回答 1

0

这似乎是一个XY 问题。我猜您想从http://www.jcao.org/mylkups.asp和其他页面获取数据,就像手动单击按钮一样。

WebClient wc = new WebClient();
string page = wc.DownloadString("http://www.jcao.org/mylkups.asp");

HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(page);

var values = doc.DocumentNode.SelectNodes("//input[@name='view']")
                .Select(t => t.Attributes["value"].Value)
                .ToList();

wc.Headers["Content-Type"] = "application/x-www-form-urlencoded";
foreach (var val in values)
{
    var newpage = wc.UploadString("http://www.jcao.org/myrec.asp", "view=" + HttpUtility.UrlEncode(val));
    Console.WriteLine(newpage);
    //
    //Now Parse that page with HtmlAgilityPack
}
于 2012-11-01T09:55:16.627 回答