且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从C#中的网页检索Ajax/JavaScript返回结果

更新时间:2023-02-23 08:40:56

此处.然后,也从堆栈溢出中取出:):

Here. then, also taken from stack overflow :):

WebBrowser mywebBrowser;
private void Form1_Load(object sender, EventArgs e)
{
 mywebBrowser = new WebBrowser();
 mywebBrowser.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(mywebBrowser_DocumentCompleted);

 Uri address = new Uri("http://www.cnn.com/");
 mywebBrowser.Navigate(address);
}

 private void mywebBrowser_DocumentCompleted(Object sender,WebBrowserDocumentCompletedEventArgs e)
 {
  //Until this moment the page is not completely loaded
  HtmlDocument doc = mywebBrowser.Document;
  HtmlElementCollection tagCollection;
  tagCollection = doc.GetElement("53c2583b1f204464d7fa9387e2ac1868");
 }

没有像jQuery那样直接通过类名获取元素的方法.如果表div的ID不稳定,则可以使用GetElementsByTagName遍历结果.然后,您可以使用GetAttribute("classname")来匹配您的"ajax_table"类.

There's no direct way to get elements by class name like with jQuery. If id of your table div isn't stable, you might use GetElementsByTagName, iterate through the results. You can then use GetAttribute("classname") to match your "ajax_table" class.