得到一网页中的全部链接的Url地址和Title?以下这个分析好像不太行var
i:integer;
begin
i:=Length(memo1.Text)-4;
for i:=1 to i do begin
if ((memo1.Text[i]='h') and (memo1.Text[i+1]='r') and (memo1.Text[i+2]='e') and (memo1.Text[i+3]='f')) then
end;
i:integer;
begin
i:=Length(memo1.Text)-4;
for i:=1 to i do begin
if ((memo1.Text[i]='h') and (memo1.Text[i+1]='r') and (memo1.Text[i+2]='e') and (memo1.Text[i+3]='f')) then
end;
解决方案 »
- Delphi开发程序在服务器运行一定时候发生的问题,请教下大家!
- 关于远程访问SQL Server2000求助
- 请问谁在双核下开发遇到这种问题???
- 调用C#写的webservices时 如果网络延时或者请求返回时间长的话 应用程序就卡 这是什么原因啊
- 如何90度旋转32位的bmp图啊?为什么我的函数只能旋转24位的bmp!
- 怎么释放windows对某个文件的占用,有时候并没有使用该文件的程序,但系统仍不让删该文件,真郁闷了!
- [★醒目]建议加入个人黑名单功能,以屏蔽自己认为恶意不结贴的人的帖子,支持的进,不支持的也进:)
- 图片怎么传输????
- 关于winsock!
- 关于多线程的一个问题,suspend之后再,resume为什么挂起的线程不能继续执行
- 关于删除文件的问题!
- 七夕----祝愿大家梦想成真
regexpstudio.com/
{作者从事了5年的web制作工作,对html语言比较熟悉,但却不懂正则表达式,因此在提取超链接时使用的是字符判断方法
考虑到html 语言中超链接可以写的很不规范,因此花了些心思来写这个函数,可以分析出大部分规范或不规范的超链接
但本函数效率不算很好,如果哪位仁兄可以改装或加强本函数,请发份到 [email protected] ,共同进步}
var
Current_pos,A_pos_left_1,A_pos_left_2,A_pos_right_1,A_pos_right_2,pos_temp_1,pos_temp_2,str_len:integer;
Temp_Ads,Temp_keyword,Href_str_all,Href_temp:string;
Href_list:TList; sea_pos,Left_blank:integer;
begin
Html_str:=LowerCase(Html_str);
if start_pos<=0 then Start_pos:=1;
Href_list:=TList.Create;
sea_pos:=start_pos;
Current_pos:=1;
while (sea_pos < Length(Html_str)) and (Current_pos>0) do
begin
Current_pos := PosEx('<a ',Html_str,sea_pos);
sea_pos:=Current_pos+1;
if Current_pos>0 then
begin
Temp_keyword := ' href';
Temp_Ads := '';
A_pos_left_1 := PosEx(Temp_keyword,Html_str,Current_pos);
if A_pos_left_1>0 then
begin
A_pos_left_1:= A_pos_left_1+length(Temp_keyword)+1;
Href_temp := midBstr(Html_str,A_pos_left_1,500); //500为设定数,一种常规的思维判断,宁愿出现1%的错误也不愿耽误60%的时间
Left_blank := length(Href_temp);
Href_temp := TrimLeft(Href_temp);
Left_blank := Left_blank-length(Href_temp);
if leftBstr(Href_temp,1)='"' then
begin
pos_temp_1 := 2;
pos_temp_2 := PosEx('"',Href_temp,2);
end else if leftBstr(Href_temp,1)='''' then
begin
pos_temp_1 := 2;
pos_temp_2 := PosEx('''',Href_temp,2);
end else
begin
pos_temp_1 := 1;
if (PosEx(' ',Href_temp,1)=0) or (PosEx(' ',Href_temp,1)>PosEx('>',Href_temp,1)) then
pos_temp_2 := PosEx('>',Href_temp,1)
else
pos_temp_2 := PosEx(' ',Href_temp,1);
end;
str_len := pos_temp_2-pos_temp_1; if pos_temp_2<pos_temp_1 then continue; Temp_Ads := Trim(MidBstr(Href_temp,pos_temp_1,str_len)); A_pos_left_1 := Left_blank+str_len+A_pos_left_1; end else
continue; A_pos_left_2 := PosEx('>',Html_str,A_pos_left_1); A_pos_right_1 := PosEx('</a',Html_str,A_pos_left_2);
A_pos_right_2 := PosEx('>',Html_str,A_pos_right_1); if (A_pos_left_1>0) and (A_pos_left_2>0) and (A_pos_right_1>0) and (A_pos_right_2>0) then
begin Href_str_all := MidBStr(Html_str,Current_pos,(A_pos_right_2-Current_pos+1));
new(Href_cont);
//地址
Href_cont^.address:= Temp_Ads;
//文字
Href_cont^.Text:=MidBStr(Href_str_all, (A_pos_left_2-Current_pos+2) ,(A_pos_right_1-A_pos_left_2-1));
Href_list.Add(Href_cont); end;
sea_pos:=A_pos_right_2+1;
end; end;
result:=Href_list;
end;
.......
type
PHref=^THref;
THref=record
Address:string; //地址
Text:string; //文字
end;
var
Form1: TForm1;
Href_cont:PHref;
implementation
.......