如果不是框架网页
可以使用for循环查询links集合的方式获取所有链接
但是在框架网页中
这种方法得不到链接
请问如何解决?

解决方案 »

  1.   

    uses MSHTML;procedure TForm1.FormCreate(Sender: TObject);
    begin
      WebBrowser1.Navigate('http://community.csdn.net');
    end;procedure TForm1.WebBrowser1DocumentComplete(Sender: TObject;
      const pDisp: IDispatch; var URL: OleVariant);  procedure pScanFrames(mHTMLDocument2: IHTMLDocument2);
      var
        vIndex: OleVariant;
        I: Integer;
        vDispatch: IDispatch;
        vHTMLAnchorElement: IHTMLAnchorElement;
      begin
        if not Assigned(mHTMLDocument2) then Exit;
        for I := 0 to mHTMLDocument2.links.length - 1 do
        begin
          vHTMLAnchorElement := (mHTMLDocument2.links.item(I, 0) as IHTMLAnchorElement);
          Memo1.Lines.Add(vHTMLAnchorElement.href);
        end;
        for I := 0 to mHTMLDocument2.frames.length - 1 do
        begin
          vIndex := I;
          vDispatch := mHTMLDocument2.frames.item(vIndex);
          pScanFrames((vDispatch as IHTMLWindow2).document);
        end;
      end;
    begin
      Memo1.Clear;
      if not SameText('http://community.csdn.net/', URL) then Exit;
      pScanFrames(TWebBrowser(Sender).Document as IHTMLDocument2);
    end;
      

  2.   

    再麻烦一下楼上的大大~
    在某个网站试验的时候~
    提示"拒绝访问"~
    break以后停在这一句:
    pScanFrames((vDispatch as IHTMLWindow2).document);
    这是为什么?
      

  3.   

    这可能是M$的安全限制
    如果框架里的网页连接是另一个域名,则不能访问该框架的document等接口
    避免一些人的流氓行为--把别人的网页嵌到自己的页面,并修改其内容
      

  4.   

    write your own browser on TCP/IP
      

  5.   

    好吧~
    那用IdHTTP读框架中各个页面的源代码有可能么?
    还有这个网页是Session验证的~
      

  6.   

    Sure
    You are free to change the request headers and interpret the responses.