从例子中你学到的知识比你学书本更容易记忆
现在做一个手机号查询工具,他是利用www.ip138.com来查的
主要用到webbrowser
利用pos()从源码中找出你想要的数据
还有一点,有些控件我没有办法去隐藏,只能用别有一些控件来覆盖起来,从而程序看起来美观
一会我发出代码,但希望你一看就懂,不懂的在提出问题来,我在第一时间回答你的问题
下载这个程序源码:
http://www.cnitblog.com/Files/shuyezi122/手机号查寻工具.rar
发出主要代码:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, mshtml, StdCtrls, Buttons, OleCtrls, SHDocVw, ExtCtrls, Mask;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
PostEdit: TBitBtn;
PostStr: TEdit;
Label1: TLabel;
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit5: TEdit;
Edit4: TEdit;
Edit6: TEdit;
zhang: TEdit;
Image1: TImage;
procedure HandPostButClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure PostEditMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure WebBrowser1NavigateComplete2(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
procedure Button1Click(Sender: TObject);
procedure WebBrowser1DownloadComplete(Sender: TObject);
procedure PostStrKeyPress(Sender: TObject; var Key: Char);
procedure PostEditClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
myitem:Olevariant;
implementation
{$R *.dfm}
procedure TForm1.HandPostButClick(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.ip138.com:8080/search.asp');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
webbrowser1.Navigate('http://www.ip138.com:8080/search.asp');
end;
procedure TForm1.PostEditMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
i:integer;
begin
myitem := WebBrowser1.Document;
for i := 0 to myitem.all.length - 1 do
begin
if myitem.all.item(i).tagName = 'INPUT' then
begin
if Uppercase(myitem.all.item(i).name)='MOBILE' then
myitem.all.item(i).value:=PostStr.Text;
end;
end;
for i := 0 to myitem.all.length - 1 do
begin
if myitem.all.item(i).tagName = 'INPUT' then
begin
if Uppercase(myitem.all.item(i).type)='SUBMIT' then
begin
if Uppercase(myitem.all.item(i).value)='查 询' then myitem.all.item(i).click; // 点击提交键
end;
end;
end;
end;
procedure TForm1.WebBrowser1NavigateComplete2(Sender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
begin
myitem := WebBrowser1.Document;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
s,IPSTR , IPSTR1 : String;
iPos,i : Integer;
begin
edit1.Text:=poststr.Text;
IPSTR:=myitem.all.item(1).outerhtml;
iPos := Pos('卡号归属地',IPSTR);
if iPos <> 0 then
edit2.Text:= Copy(IPSTR,iPos+53,4);
edit6.Text:= Copy(IPSTR,iPos+63,4);
iPos := Pos('卡 类 型',IPSTR);
if iPos <> 0 then
edit3.Text:= Copy(IPSTR,iPos+61,9);
iPos := Pos('区 号',IPSTR);
if iPos <> 0 then
zhang.Text:=Copy(IPSTR,iPos+40,4);
if zhang.Text[4] in ['0'..'9'] then
edit4.text:=zhang.text
else
begin
s:=zhang.Text;
setlength(s,3);
edit4.text:=s;
end;
iPos := Pos('邮 编',IPSTR);
if iPos <> 0 then
edit5.Text:= Copy(IPSTR,iPos+40,6);
end;
procedure TForm1.WebBrowser1DownloadComplete(Sender: TObject);
begin
postedit.Enabled:=true;
end;
procedure TForm1.PostStrKeyPress(Sender: TObject; var Key: Char);
begin
if not (key in ['0'..'9',#8]) then
begin
application.MessageBox('手机号只能是数字','提示',64);
key:=#0;
poststr.SetFocus;
end;
end;
procedure TForm1.PostEditClick(Sender: TObject);
begin
button1.Enabled:=true;
end;
end.
posted on 2009-01-05 23:12
小叶子 阅读(745)
评论(1) 编辑 收藏 引用 所属分类:
delphi网络编程