关于网页字符查找存库的问题(200分),谢谢老大!(200分)

  • 主题发起人 主题发起人 szw3000
  • 开始时间 开始时间
S

szw3000

Unregistered / Unconfirmed
GUEST, unregistred user!
2003-11-23 21:15<br>to <a href="kkvi.asp?username=!#$#%@#%#@">szw3000</a></td>
以上是一个论坛页面的原程序一部分,我想要做的事情就是如何把用户名szw3000找出来并建立一个文本保存这些用户名。
找了好久没看见合适的(太笨了),请老大们帮帮忙,200分求答案谢谢了
 
把该html做为一个xml来处理吧,利用xml parse类的工具或控件来做我认为比较方便
当然你也可以直接读取该html然后分析语法,如果纯只是为了提取该用户名的话,这个语法分析工作也不是很难。
 
Response.Write Request("UserName")
 
参考一下,对你有用,没时间再重写程序了!
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1414973
http://www.delphibbs.com/delphibbs/dispq.asp?lid=1408891


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdHTTP, ComCtrls;

type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
Panel1: TPanel;
Edit1: TEdit;
Button1: TButton;
Memo1: TMemo;
ProgressBar1: TProgressBar;
procedure Button1Click(Sender: TObject);
procedure IdHTTP1WorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
procedure IdHTTP1WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
procedure IdHTTP1Work(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
private
{ Private declarations }
public
{ Public declarations }
procedure getLink(str:String);
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
body:String;
begin
Memo1.Clear;
body:=idHTTP1.Get(Edit1.Text); //得到html源文件
//Memo1.Text:=body;
getLink(body);
end;

procedure TForm1.IdHTTP1WorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
begin
ProgressBar1.Max:= AWorkCountMax;
end;

procedure TForm1.IdHTTP1WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
begin
ProgressBar1.Position:= 0;
end;

procedure TForm1.IdHTTP1Work(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
begin
ProgressBar1.Position:= AWorkCount;
end;

procedure TForm1.getLink(str: String);
var
i,j:Integer;
isLink:Boolean;
tmpurl:String;

function geturl(linkStr:String):String;
var
eqpos,m,n,lsLen:Integer;
tmpLink:String;
begin
Result:='';
eqpos:=Pos('=',linkStr);
lsLen:=Length(linkStr);
if linkStr[eqpos+1]='"' then begin
for m := 0 to lsLen-1 do
begin
if linkStr[m+eqpos+2]='"' then break;
end;
tmpLink:=copy(linkStr,eqpos+2,m);
if ExtractFileExt(tmpLink)='.exe' then Result:=tmpLink;
end
else
begin
for n := 0 to lsLen-1 do
begin
if (linkStr[n+eqpos+1]=' ') or (linkStr[n+eqpos+1]='>') then break;
end;
tmpLink:=copy(linkStr,eqpos+1,n);
if ExtractFileExt(tmpLink)='.exe' then Result:=tmpLink;
end;
end;

begin
isLink:=false;
for i := 0 to Length(str)-1 do
begin
if str+str[i+1]='<a' then isLink:=true;
if str+str[i+1]+str[i+2]+str[i+3]='<src' then isLink:=true;
if isLink then begin
for j := 0 to Length(str)-i-1 do
begin
if str[i+j]='>' then begin
break;
end;
end;
tmpurl:=geturl(copy(str,i,j+1));
if Pos('exe',tmpurl)>0 then Memo1.Lines.Add(tmpurl);
isLink:=false;
end;

end;

end;

end.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
I
回复
0
查看
795
import
I
后退
顶部