已知该html的url,html的内容,
如何分析出该html链接的所有url?
要求在比较准确的境况下,尽量提高执行效率。

解决方案 »

  1.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      ShellWindow: IShellWindows;
      nCount: integer;
      spDisp: IDispatch;
      i: integer;
      vi: OleVariant;
      IE1: IWebBrowser2;
      IDoc1: IHTMLDocument2;
    begin
      ShellWindow := CoShellWindows.Create;
      nCount := ShellWindow.Count;  for i := 0 to nCount - 1 do
      begin
        vi := i;
        spDisp := ShellWindow.Item(vi);
        spDisp.QueryInterface( iWebBrowser2, IE1 );
        if IE1 <> nil then
        begin
          memo1.Lines.Add( 'Location: '+ie1.LocationName );      IE1.Document.QueryInterface(IHTMLDocument2,iDoc1);
          if iDoc1 <> nil then
          begin
            memo1.Lines.add( 'Title: ' + IDOC1.Title );
            memo1.Lines.add( 'Url: ' + IDOC1.url);
          end;
        end;
      end;
    end;
      

  2.   

    刚才那个不是,试试这个:
    unit ligwin1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type
      TForm1 = class(TForm)
        Label1: TLabel;
        Label2: TLabel;
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        { Private declarations }
        control,KeyId:integer;
        hotkeyid:ATOM;
      public
        { Public declarations }
        procedure WMHOTKEY(var Msg:TMessage);message WM_HOTKEY;
      end;var
      Form1: TForm1;
      ThisUrl:PChar;implementation{$R *.DFM}
    function EnumChildWindowsProc(H:HWnd;lparam:longint):Boolean;stdcall;
    var
      Buffer: array[0..10] of Char;
    begin
      Result:=True;
      GetClassName(h,buffer,10);
      if trim(StrPas(Buffer))='Edit' then
      begin
        SendMessage(h,WM_GETTEXT,249,Integer(ThisUrl));
        Result:=False;
      end;
    end;procedure TForm1.WMHOTKEY(var Msg:TMessage);
    var
     h:HWND;
     buffer:array[0..256] of char;
     temp:String;
    begin
     if (Msg.LParamHi=KeyId) and (Msg.LParamLo=control) then
       begin
        Msg.Result:=1;
        h:=GetForegroundWindow;
        GetClassName(h,buffer,255);
        if StrPas(buffer)='IEFrame' then
          begin
           EnumChildWindows(h,@EnumChildWindowsProc,0);
           GetWindowText(h,buffer,255);
           buffer[Pos(' - ',buffer)]:=Char(0);
           temp:='当前网页的URL是:'+ThisUrl+#13#10+'当前网页Title是:'+buffer;
           MessageBox(h,PChar(temp),'提示信息',MB_OK)
          end;
       end;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
     ThisUrl:=StrAlloc(250);
     control:=MOD_CONTROL or MOD_SHIFT ;KeyId:=$43;
     hotkeyid:=GlobalAddAtom('UserDefineHotKey')-$C000;
     RegisterHotKey(Handle,hotkeyid,control,KeyId);
    end;procedure TForm1.FormDestroy(Sender: TObject);
    begin
     UnregisterHotKey(Handle,hotkeyid);
     DeleteAtom(hotkeyid);
    end;end.
      

  3.   

    你好象误解了我的意思,
    我不是要得到ie中的当前网址,
    我的意思是要解析html文本,得到url
      

  4.   

    两种方案:
    1.通过MSHTML封装的COM接口
    2.自己编写HTML解析引擎要哪种?http://renzhen.org/article/list.asp?id=187
      

  5.   

    可惜不是PERL,不能用正则表达式。那估计是高效的,
    听说BOOST里面的那个REG什么的处理表达式的都比PERL的慢。
      

  6.   

    http://www.vclxx.org/DELPHI/D32FREE/REGEXPR.ZIP下载上面这个单元文件,即可获得对正则表达式的支持,当然如果不想自己编写,用MS提供的COM接口是最方便的!
      

  7.   

    提取原代码,再查找<a href>.....</a> 把这段文本拷到剪切板就可以,
    就是不知道怎么提取原代码!哈哈做个记号。
      

  8.   

    如果是<a name="xxx" href="...">...</a>呢?如果双引号换成单引号,如果没有引号,如果...!也把问题太简单化了,取HTML代码倒是真的很简单!论坛里找找!
      

  9.   

    其实用NMhttp控件就可得到原代码,只不过还得把现在IE中的地址传给他
      

  10.   

    如果按照标准规范来解析HTML代码是很简单的,可问题是网络上大量的网页都是不
    规范的,IE的兼容性好,也能显示出来,但是你自己做,也想做到这样高的兼容性可不太容易。
      

  11.   

    软件报有个连载,是关于falshGet和NetAnt二次开发的。就有你想要的。
    以FlashGet为例,装完后其中的文件jc_all.htm,就是用来提取所有网页上链接的。对应命令是使用网际快车下载全部链接,jc_link.htm用来提取当前链接,对就命令是使用网际快车下载。
      

  12.   

    网页上有一个文本连接例如:
    首页,它的连接属性是http://www.csdn.net
    楼主问的是如何得到http://www.csdn.net!
      

  13.   

    在C++用boost里面的REGEX,自带的例子2就是用来做这种事情的
    不过我转到WIN里面去看了一下,编译好大,160K左右
      

  14.   

    那个函数的接口就是这个了。
    void parser(const std::string& fromfile,std::list<std::string>& slist)
      

  15.   

    给个信箱,我已经实现了。并且支持带框架的网页。注册新浪9M纯免费邮箱 -  http://members.sina.com.cn/emailchart.html
    注册邮箱 -  http://members.sina.com.cn/apply/
    企业邮箱 -  http://mail.sina.net/
    首页 -  http://www.sina.com.cn/
    新闻 -  http://news.sina.com.cn/
    娱乐 -  http://ent.sina.com.cn/
    游戏 -  http://games.sina.com.cn/
    男性 -  http://man.sina.com.cn/
    宠物 -  http://bj.sina.com.cn/pet/
    旅游 -  http://travel.sina.com.cn/
    文化 -  http://cul.sina.com.cn/
    邮箱 -  http://mailhome.sina.com.cn/
    北京 -  http://bj.sina.com.cn/
    同学录 -  http://viafriend.sina.com.cn/
    企业 -  http://www.sina.net/
    短信 -  http://sms.sina.com.cn/
    搞笑 -  http://sms.sina.com.cn/docs/c/fcxh.html?from=425
    体育 -  http://sports.sina.com.cn/
    搜索 -  http://search.sina.com.cn/
    无线 -  http://wireless.sina.com.cn/
    军事 -  http://jczs.sina.com.cn/
    女性 -  http://eladies.sina.com.cn/
    星座 -  http://astro.sina.com.cn/
    城市 -  http://city.sina.net/
    读书 -  http://book.sina.com.cn/
    饮食 -  http://eat.sina.com.cn/
    上海 -  http://sh.sina.com.cn/
    高尔夫 -  http://golf.sina.com.cn/
    招商 -  http://gov.sina.net/
    订阅 -  http://sms.sina.com.cn/ringtone/custom.shtml
    图片 -  http://sms.sina.com.cn/ringtone/piclist.shtml
    科技 -  http://tech.sina.com.cn/
    汽车 -  http://auto.sina.com.cn/
    培训 -  http://edu.sina.com.cn/el/
    留学 -  http://edu.sina.com.cn/a/index.shtml
    英语 -  http://edu.sina.com.cn/en/index.shtml
    育儿 -  http://baby.sina.com.cn/
    贺卡 -  http://ecards.sina.com.cn/
    动漫 -  http://comic.sina.com.cn/
    笑话 -  http://newbbs4.sina.com.cn/index.shtml?living:xiaohua
    广东 -  http://gd.sina.com.cn/
    下载区 -  http://tech.sina.com.cn/down/
    黄页 -  http://yp.sina.net/
    交友 -  http://love.meme.com.cn/
    铃声 -  http://sms.sina.com.cn/ringtone/ringtone.shtml
    财经 -  http://finance.sina.com.cn/
    房产 -  http://housing.sina.com.cn/
    教育 -  http://edu.sina.com.cn/
    出国 -  http://edu.sina.com.cn/m/
    健康 -  http://511511.sina.com.cn/
    商城 -  http://mall.sina.com.cn/
    天气 -  http://weather.sina.com.cn/
    论坛 -  http://people.sina.com.cn/forum.html
    聊天 -  http://chat.sina.com.cn/
    扬州 -  http://yz.sina.com.cn/
    嘉 宾 -  http://people.sina.com.cn/guest/
    分类 -  http://classad.sina.com.cn/
    星梦 -  http://yoyorock.sina.com.cn/
    彩信 -  http://mms.sina.com.cn/
    北京大学英语自考部招生 -  http://sina.allyes.com/main/adfclick?db=sina&bid=810,3934,3950&cid=0,0,0&sid=4094&show=ignore&url=http://shangguang.longsu.net/beida/
    中科院在职研究生(秋季) -  http://sina.allyes.com/main/adfclick?db=sina&bid=20,49,49&cid=0,0,0&sid=49&show=ignore&url=http://www.edu-china.cn
    首都高校扩招! -  http://sina.allyes.com/main/adfclick?db=sina&bid=367,1180,1181&cid=0,0,0&sid=1211&show=ignore&url=http://www.bydsoft.com/
    中国管理软件学院 -  http://sina.allyes.com/main/adfclick?db=sina&bid=16,34,34&cid=0,0,0&sid=34&url=http://www.aa55.com/index.asp&show=ignore
    欧园TWO HOUSE现房登场! -  http://sina.allyes.com/main/adfclick?db=sina&bid=370,1190,1191&cid=0,0,0&sid=1221&show=ignore&url=http://www.beiouyinxiang.com
    北大经理人班 CFO班 -  http://sina.allyes.com/main/adfclick?db=sina&bid=16,36,36&cid=0,0,0&sid=36&url=http://econ.yp.sina.net/&show=ignore
    万柳精装小户型