从区域获取html元素

时间:2011-10-27 12:46:13

标签: c# html

有没有办法从所选区域(矩形)的浏览器中获取html源(所有元素)? 有 WebBrowser.Document.GetElementFromPoint ,但这意味着,我必须遍历整个文档......

提前致谢

1 个答案:

答案 0 :(得分:0)

你可以尝试这样..来获取当前文档中的所有元素

   // start an instance of IE
public SHDocVw.InternetExplorerClass ie;
ie = new SHDocVw.InternetExplorerClass();
ie.Visible = true;

// Load a url
Object Flags = null, TargetFrameName = null, PostData = null, Headers = null;
ie.Navigate( url, ref Flags, ref TargetFrameName, ref PostData, ref Headers );

while( ie.Busy )
{
  Thread.Sleep( 500 );
}

// get an element from the loaded document
mshtml.HTMLDocumentClass document = ((mshtml.HTMLDocumentClass)ie.Document);
document.getElementById("myelementsid");