2种方法:1. memo1.lines.add(idhttp1.get('http://www.abcxxxx.com/cgi-bin/xxxx.cgi'));2. interface uses mshtml;some procedure; var html:IHTMLDocument; begin html:=webbrowser1.document as IHTMLDocument; memo1.text:=doc.body.innerhtml; end;
procedure TForm1.Button2Click(Sender: TObject); var len,i:integer; item:oleVariant; innertext,href:string; doc:IHTMLDocument2; link:IHTMLElementCollection; begin //read html source doc:=webbrowser1.document as IHTMLDocument2; link:=doc.get_links; len:=link.length; for i:=0 to len-1 do begin item:=link.item(i,varempty); innertext:=item.innertext; href:=item.href; //innertext是超级连接的显示部分 //href是超级连接的连接 end; end;
memo1.lines.add(idhttp1.get('http://www.abcxxxx.com/cgi-bin/xxxx.cgi'));2.
interface uses mshtml;some procedure;
var html:IHTMLDocument;
begin
html:=webbrowser1.document as IHTMLDocument;
memo1.text:=doc.body.innerhtml;
end;
procedure TForm1.PutData;varShellWindow: IShellWindows;nCount: integer;spDisp: IDispatch;i,j,X: integer;vi: OleVariant;IE1: IWebBrowser2;IDoc1: IHTMLDocument2;iELC : IHTMLElementCollection ;S,S2 : string;HtmlInputEle : IHTMLInputElement;HtmlSelEle : IHTMLSelectElement;beginShellWindow := CoShellWindows.Create;nCount := ShellWindow.Count;for i := 0 to nCount - 1 dobeginvi := i;spDisp := ShellWindow.Item(vi);if spDisp = nil then continue;spDisp.QueryInterface( iWebBrowser2, IE1 );if IE1 <> nil thenbeginIE1.Document.QueryInterface(IHTMLDocument2,iDoc1);if iDoc1 <> nil thenbeginielc:=idoc1.Get_all;for j:=0 to ielc.length-1 dobeginApplication.ProcessMessages;spDisp := ielc.item(J, 0);if SUCCEEDED(spDisp.QueryInterface(IHTMLInputElement ,HtmlInputEle))thenwith HtmlInputEle dobeginS2:=Type_;S2:=UpperCase(S2);//我把所有的input都填上 try , checkbox 都打勾if (StrComp(PChar(S2),'TEXT')=0) or (StrComp(PChar(S2),'PASSWORD')=0) thenvalue :='try' //S:=S+#9+Valueelse if StrComp(PChar(S2),'CHECKBOX')=0 thenbeginchecked := True;end;end;if SUCCEEDED(spDisp.QueryInterface(IHTMLselectelement ,HtmlSelEle))thenwith HtmlSelEle, Memo1.Lines dobeginS:=S+#9+IntToStr(selectedIndex+1); //这个是获取数据了end;end; //END FORMemo2.Lines.Add(S);exit;end;end;end;end;
这样会快很多。
当然啦...我们只下字符嘛...
var
len,i:integer;
item:oleVariant;
innertext,href:string;
doc:IHTMLDocument2;
link:IHTMLElementCollection;
begin
//read html source
doc:=webbrowser1.document as IHTMLDocument2;
link:=doc.get_links;
len:=link.length;
for i:=0 to len-1 do
begin
item:=link.item(i,varempty);
innertext:=item.innertext;
href:=item.href;
//innertext是超级连接的显示部分
//href是超级连接的连接
end;
end;