得到一网页中的全部链接的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;

解决方案 »

  1.   

    我的方法是通过MSHTML提供的MarkupService服务将HTML源代码转换成DOM,然后通过document.all来访问所有节点,对比每个节点中是否存在包含链接的属性,例如<a>就找href,<iframe>就找src。一次类推。这种方法的好处是不仅可以找到一般的绝对地址,也可以找到相对地址。远远比使用正则表达式来挖取精确。但是正则表达式则方便了很多。正则表达式Delphi版本下载地址:
    regexpstudio.com/
      

  2.   

    function TForm1.Get_Href(Html_str:string;start_pos:integer):Tlist;
    {作者从事了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;
      

  3.   

    忘了这个
    .......
    type
      PHref=^THref;
      THref=record
        Address:string;  //地址
        Text:string;     //文字
     end;
    var
      Form1: TForm1;
      Href_cont:PHref;
    implementation
    .......