c\#IE 브 라 우 저 에서 현재 페이지 의 내용 가 져 오기
private void timer1_Tick(object sender, EventArgs e)
{
lock (currentLock)
{
System.Drawing.Point MousePoint = System.Windows.Forms.Form.MousePosition;
if (_leftClick)
{
timer1.Stop();
_leftClick = false;
_lastDocument = GetHTMLDocumentFormHwnd(GetPointControl(MousePoint, false));
if (_lastDocument != null)
{
if (_getDocument)
{
_getDocument = true;
try
{
string url = _lastDocument.url;
string html = _lastDocument.documentElement.outerHTML;
string cookie = _lastDocument.cookie;
string domain = _lastDocument.domain;
var resolveParams = new ResolveParam
{
Url = new Uri(url),
Html = html,
PageCookie = cookie,
Domain = domain
};
RequetResove(resolveParams);
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(ex.Message);
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
}
}
else
{
new MessageTip().Show("xx", " IE , IE , , 。 IE ");
}
_getDocument = false;
}
else
{
_pointFrm.Left = MousePoint.X + 10;
_pointFrm.Top = MousePoint.Y + 10;
}
}
}열 한 줄 의 GetHTMLDocumentFormHwnd(GetPointControl(MousePoint, false)) 분 해 된 다음 마우스 좌표 에서 페이지 의 핸들 을 가 져 옵 니 다:
public static IntPtr GetPointControl(System.Drawing.Point p, bool allControl)
{
IntPtr handle = Win32APIsFull.WindowFromPoint(p);
if (handle != IntPtr.Zero)
{
System.Drawing.Rectangle rect = default(System.Drawing.Rectangle);
if (Win32APIsFull.GetWindowRect(handle, out rect))
{
return Win32APIsFull.ChildWindowFromPointEx(handle, new System.Drawing.Point(p.X - rect.X, p.Y - rect.Y), allControl ? Win32APIsFull.CWP.ALL : Win32APIsFull.CWP.SKIPINVISIBLE);
}
}
return IntPtr.Zero;
}다음,핸들 에 따라 페이지 내용 가 져 오기:
public static HTMLDocument GetHTMLDocumentFormHwnd(IntPtr hwnd)
{
IntPtr result = Marshal.AllocHGlobal(4);
Object obj = null;
Console.WriteLine(Win32APIsFull.SendMessageTimeoutA(hwnd, HTML_GETOBJECT_mid, 0, 0, 2, 1000, result));
if (Marshal.ReadInt32(result) != 0)
{
Console.WriteLine(Win32APIsFull.ObjectFromLresult(Marshal.ReadInt32(result), ref IID_IHTMLDocument, 0, out obj));
}
Marshal.FreeHGlobal(result);
return obj as HTMLDocument;
}대략적인 원리:
IE 창 에 메 시 지 를 보 내 IE 브 라 우 저(비 위탁 관리)를 가리 키 는 메모리 블록 을 가 져 온 다음 이 지침 에 따라 HTML Document 대상 을 가 져 옵 니 다.
이 방법 은 win 32 의 두 함수 와 관련된다.
[System.Runtime.InteropServices.DllImportAttribute("user32.dll", EntryPoint = "SendMessageTimeoutA")]
public static extern int SendMessageTimeoutA(
[InAttribute()] System.IntPtr hWnd,
uint Msg, uint wParam, int lParam,
uint fuFlags,
uint uTimeout,
System.IntPtr lpdwResult);
[System.Runtime.InteropServices.DllImportAttribute("oleacc.dll", EntryPoint = "ObjectFromLresult")]
public static extern int ObjectFromLresult(
int lResult,
ref Guid riid,
int wParam,
[MarshalAs(UnmanagedType.IDispatch), Out]
out Object pObject
);이상 은 c\#IE 브 라 우 저 에서 현재 페이지 의 내용 을 가 져 오 는 상세 한 내용 입 니 다.c\#브 라 우 저 페이지 의 내용 을 가 져 오 는 자 료 는 다른 관련 글 을 주목 하 십시오!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
C#Task를 사용하여 비동기식 작업을 수행하는 방법라인이 완성된 후에 이 라인을 다시 시작할 수 없습니다.반대로 조인(Join)만 결합할 수 있습니다 (프로세스가 현재 라인을 막습니다). 임무는 조합할 수 있는 것이다. 연장을 사용하여 그것들을 한데 연결시키는 것이...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.