从区域获取html元素

本文关键字:元素 html 获取 区域 | 更新日期: 2023-09-27 18:12:28

是否有任何方法从选定区域(矩形)的浏览器中获取html源(所有元素)?有 WebBrowser.Document.GetElementFromPoint ,但这意味着,我必须循环遍历整个文档…

Thanks in advance

从区域获取html元素

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

   // 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");