请教不通过网页原代码获取网页内所有URL的方法     注意是不通过网页原代码     最好有现成的函数或者组件

解决方案 »

  1.   

    //可以枚举所有的网页链接,然后循环取出即可。
    //下面是代码:
    //已经调试通过,注意:要在uses里引用mshtml单元。
    //效果图见下图:
    var
      doc: IHTMLDocument2;
      all: IHTMLElementCollection;
      len, i: integer;
      item: OleVariant;
    begin
      doc := WebBrowser1.Document as  IHTMLDocument2;
      all := doc.links;   
      len := all.length;
      for i := 0 to len-1 do
      begin
          item := all.item(i, varempty); 
          if ListBox.IndexOf(item.href) = -1   then
          begin
              ListBox1.Items.Append(item.href);
          end;
      end;
    end;
      

  2.   

    var
        doc:   IHTMLDocument2;
        all:   IHTMLElementCollection;
        len,   i:   integer;
        item:   OleVariant;
    begin
        doc   :=   WebBrowser1.Document   as     IHTMLDocument2;
        all   :=   doc.links;      
        len   :=   all.length;
        for   i   :=   0   to   len-1   do
        begin
                item   :=   all.item(i,   varempty);  
                if   ListBox.IndexOf(item.href)   =   -1       then
                begin
                        ListBox1.Items.Append(item.href);
                end;
        end;
    end; 
      

  3.   

    原始的 SCOKET + 正则表达式