1,593
社区成员
发帖
与我相关
我的任务
分享
uses SHDocVw, MSHTML, ActiveX;
procedure ExtractDocumentLinks(pHTMLDocument: IHTMLDocument2; pStrings: TStringList);
var
pAnchors: IHTMLElementCollection;
ilHrefCount, ilHrefIndex: integer;
vIndex: OleVariant;
pItem: IDispatch;
pAnchor: IHTMLAnchorElement;
bURL: string;
begin
if (pHTMLDocument <> nil) then
begin
pAnchors := pHTMLDocument.get_all;
ilHrefCount := pAnchors.get_length;
if ilHrefCount = 0 then exit;
for ilHrefIndex := 0 to ilHrefCount - 1 do
begin
TVariantArg(vIndex).vt := VT_I4;
TVariantArg(vIndex).lVal := ilHrefIndex;
pItem := pAnchors.item(vIndex, vIndex);
if(pItem <> nil) then
begin
if(SUCCEEDED(pItem.QueryInterface(IID_IHTMLAnchorElement, pAnchor))) then
begin
bURL := pAnchor.get_href;
if (pStrings.IndexOf(AnsiString(WideString(bURL))) < 0) and
(length(bURL) > 0) then
pStrings.Add(bURL);
end;
pItem := nil;
end;
end;
pAnchors := nil;
end;
end;
procedure TfrmMain.ExtractLinks(WebBrowser: IWebBrowser2; pStrings: TStringList);
var
vFrame, ret: OleVariant;
ilFrameIndex, ilFramesCount: integer;
pDoc, HTMLDocument: IHTMLDocument2;
pWindow: IHTMLWindow2;
pFrames: IHTMLFramesCollection2;
spdisp:idispatch;
HtmlInputEle,HtmlInputEle_hy2k: IHTMLInputElement;
HtmlSelEle : IHTMLSelectElement;
HtmlTextEle: IHTMLTextElement;
HtmlTextAreaEle :IHTMLTextAreaElement;
HtmlLabelEle :IHTMLLabelElement;
qymc :string;
pos1,pos2:integer;
aa :IHTMLEventObj;
dispparamsNoArgs: DISPPARAMS;
begin
if(SUCCEEDED(WebBrowser.Document.QueryInterface(
IID_IHTMLDocument2, HTMLDocument))) then
begin
pFrames:=(HTMLDocument.get_frames as IHTMLFramesCollection2);
ilFramesCount := pFrames.get_length;
if ilFramesCount < 2 then
begin
// ExtractDocumentLinks(pDoc, pStrings);
// HtmlInputEle:=(HTMLDocument.all.item('txtfddbr',0) as IHTMLInputElement);
// if HtmlInputEle <> nil then
// HtmlInputEle.value :='3';
end
else
begin
//取网页所有内容
{for ilFrameIndex := 0 to ilFramesCount - 1 do
begin
vFrame := ilFrameIndex;
spDisp := pFrames.item(vFrame);
if SUCCEEDED(spDisp.QueryInterface(IHTMLWindow2 ,pWindow))then
pStrings.Add(pWindow.document.body.innerHTML);
end; }
TVariantArg(vFrame).vt := VT_UINT;
for ilFrameIndex := 1 to ilFramesCount - 1 do
begin
TVariantArg(vFrame).lVal := ilFrameIndex;
spDisp := pFrames.item(vFrame);
if (SUCCEEDED(spDisp.QueryInterface(IID_IHTMLWindow2, pWindow))) then
begin
pDoc := pWindow.get_document;
if pDoc.title = 'XXXX' then
begin
HtmlInputEle:=(pDoc.all.item('test11',0) as IHTMLInputElement);
if HtmlInputEle <> nil then
begin
HtmlInputEle.select;
HtmlInputEle.value :='111';
vi2 := HtmlInputEle.get_onchange; // 事件
ev := IDispatch(vi2);
dispparamsNoArgs.rgvarg := nil;
dispparamsNoArgs.rgdispidNamedArgs := nil;
dispparamsNoArgs.cArgs := 0;
dispparamsNoArgs.cNamedArgs := 0;
ev.Invoke(
DISPID_VALUE,
GUID_NULL,
LOCALE_USER_DEFAULT,
DISPATCH_METHOD,
dispparamsNoArgs,
@vr,
nil,
nil);
end;
end;
pDoc := nil;
pWindow := nil;
end;
end;
end;
end;
end;