procedure TForm1.Button2Click(Sender: TObject); begin //WebBrowser1.Navigate(PChar('http://www.yiwant.com/cgi-bin/sn.cgi'), WebBrowser1.Navigate(PChar('http://www.yiwant.com/shouji114.htm'), EmptyParam,EmptyParam,EmptyParam,EmptyParam); IsFind:= false; end;procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject; const pDisp: IDispatch; var URL: OleVariant); var i: Integer; IDoc: IHTMLDocument2; iELC : IHTMLElementCollection ; S : string; HtmlInputEle : IHTMLInputElement; HtmlEle: IHTMLElement; //HtmlSelEle : IHTMLSelectElement; spDisp: IDispatch; //HtmlEleCol: IHTMLElementCollection; ovDoc: oleVariant; begin IDoc:= WebBrowser1.Document as IHTMLDocument2; iELC:= IDoc.Get_all; for i:=0 to iELC.length-1 do begin Application.ProcessMessages; Sleep(10); spDisp:= iELC.item(i,0); if SUCCEEDED(spDisp.QueryInterface(IHTMLInputElement ,HtmlInputEle)) then begin s:= HtmlInputEle.name; if ((HtmlInputEle.type_ = 'text') and (HtmlInputEle.name = 'keyword')) then begin HtmlInputEle.value:= Edit1.Text; end; if ((HtmlInputEle.type_ = 'submit') and (HtmlInputEle.value = '提交')) then begin HtmlInputEle.form.submit; s:=HtmlInputEle.form.action; //Memo1.Lines.Add(s); end; end; end; if SUCCEEDED(spDisp.QueryInterface(IHTMLElement, HTMLEle)) then begin //Memo2.Lines.Add(HTMLEle.className); ovDoc:= (Sender as TWebBrowser).Document; s:= ovDoc.All.item.innerhtml; //Memo2.Text:= s; Label1.Caption:= SearchPlace(s); //if s <>'' then //WebBrowser1.Stop; end; end;function TForm1.SearchPlace(sPlace: String): String; var iPos: Integer; s: String; begin //s:= 'sorry,Nothing!'; iPos:= pos(Edit1.Text,sPlace); if iPos > 0 then begin sPlace:= Copy(sPlace,iPos,Length(sPlace)); iPos:= Pos('align=center>',sPlace); if iPos > 0 then begin sPlace:= Copy(sPlace,iPos+13 ,Length(sPlace)); iPos:= Pos('</P></TD>',sPlace); if iPos > 0 then begin s:= Copy(sPlace,1,iPos-1); end; end; end; if s<>'' then WebBrowser1.Stop; if s = '没搞错吗?那真是不好意思了。' then s:= 'sorry,没有找到!'; IsFind:= false; Result:= s; end;以上是我做的一个查手机所属地的关键源代码,其实现算法很简单 先找到网页中的edit和button控件,然后辅值后提交(submit),页面显示完成后得到整个网页的源代码,然后通过字符串分析得到手机的归属地,你看看,应该对你有用的
begin
//WebBrowser1.Navigate(PChar('http://www.yiwant.com/cgi-bin/sn.cgi'),
WebBrowser1.Navigate(PChar('http://www.yiwant.com/shouji114.htm'),
EmptyParam,EmptyParam,EmptyParam,EmptyParam);
IsFind:= false;
end;procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var
i: Integer;
IDoc: IHTMLDocument2;
iELC : IHTMLElementCollection ;
S : string;
HtmlInputEle : IHTMLInputElement;
HtmlEle: IHTMLElement;
//HtmlSelEle : IHTMLSelectElement;
spDisp: IDispatch;
//HtmlEleCol: IHTMLElementCollection;
ovDoc: oleVariant;
begin
IDoc:= WebBrowser1.Document as IHTMLDocument2;
iELC:= IDoc.Get_all;
for i:=0 to iELC.length-1 do
begin
Application.ProcessMessages;
Sleep(10);
spDisp:= iELC.item(i,0);
if SUCCEEDED(spDisp.QueryInterface(IHTMLInputElement ,HtmlInputEle)) then
begin
s:= HtmlInputEle.name; if ((HtmlInputEle.type_ = 'text') and
(HtmlInputEle.name = 'keyword')) then
begin
HtmlInputEle.value:= Edit1.Text;
end;
if ((HtmlInputEle.type_ = 'submit') and
(HtmlInputEle.value = '提交')) then
begin
HtmlInputEle.form.submit;
s:=HtmlInputEle.form.action;
//Memo1.Lines.Add(s);
end;
end;
end;
if SUCCEEDED(spDisp.QueryInterface(IHTMLElement, HTMLEle)) then
begin
//Memo2.Lines.Add(HTMLEle.className);
ovDoc:= (Sender as TWebBrowser).Document;
s:= ovDoc.All.item.innerhtml;
//Memo2.Text:= s;
Label1.Caption:= SearchPlace(s);
//if s <>'' then
//WebBrowser1.Stop;
end;
end;function TForm1.SearchPlace(sPlace: String): String;
var
iPos: Integer;
s: String;
begin
//s:= 'sorry,Nothing!';
iPos:= pos(Edit1.Text,sPlace);
if iPos > 0 then
begin
sPlace:= Copy(sPlace,iPos,Length(sPlace));
iPos:= Pos('align=center>',sPlace);
if iPos > 0 then
begin
sPlace:= Copy(sPlace,iPos+13 ,Length(sPlace));
iPos:= Pos('</P></TD>',sPlace);
if iPos > 0 then
begin
s:= Copy(sPlace,1,iPos-1);
end;
end;
end;
if s<>'' then WebBrowser1.Stop;
if s = '没搞错吗?那真是不好意思了。' then
s:= 'sorry,没有找到!';
IsFind:= false;
Result:= s;
end;以上是我做的一个查手机所属地的关键源代码,其实现算法很简单
先找到网页中的edit和button控件,然后辅值后提交(submit),页面显示完成后得到整个网页的源代码,然后通过字符串分析得到手机的归属地,你看看,应该对你有用的
以提取该网页中一些所需要的文字,要是能够将 .html 文件还原成源码提取出来存为 .txt文件 然后对 txt文件进行操作也可以,拜托,帮帮忙!!!!
然后:Memo1.Lines.LoadFromFile('c:\lhp.html');