已知某个网页的网址,如http://www.***.com/abc/index.htm,怎样得到该网页源文件里某种文件类型的链接地址?假设上述网页源文件为:
<html>
......
<src="../abc/XXX.exe">
<a href="../abc/XXX.jpg">
<src="../abc/xyz/YYY.exe>
......
</html>
如何才能获得其中所有扩展名为.exe文件的那串地址,比如该例子就是
../abc/XXX.exe 
../abc/xyz/YYY.exe
并把所有扩展名为.exe文件的地址分别保存到一个字符串变量里?
用一个Edit控件(用于输入上面那个网址),一个Button控件(按下后开始上述操作,并
得到最后那个保存了.exe文件地址的变量)。特别注意的是,事先并不知道该网页源文件里有多少个.exe文件的链接,另外要把每个.exe文件的链接地址(如上述两个地址)分别保存在不同的字符串变量里。注意最后需要的地址是../abc/XXX.exe 这样的,而不是这种<src="../abc/XXX.exe">带中括号和引号的。以上是我的问题,我是初学者,这问题在书上又找不到答案,已经困扰我好多天了,
实在没办法,我现在真的很着急啊,请各位一定帮忙!
还请知道的朋友附上完整的源代码,最好能有简单的说明,我好慢慢研究。
源代码有效的话,我一会儿马上给您加上100分,绝不食言。
先谢谢大家了!

解决方案 »

  1.   

    unit Main;interfaceuses
        Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
        Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
        IdHTTP, StdCtrls, ExtCtrls, IdAntiFreezeBase, IdAntiFreeze;type
        TForm1 = class(TForm)
            Button1: TButton;
            Http: TIdHTTP;
            Image1: TImage;
            Edit1: TEdit;
            Button2: TButton;
            Panel1: TPanel;
            Memo1: TMemo;
            ListBox1: TListBox;
            Splitter1: TSplitter;
            Button3: TButton;
            Edit2: TEdit;
            IdAntiFreeze1: TIdAntiFreeze;
            ListBox2: TListBox;
            Splitter2: TSplitter;
        Timer1: TTimer;
            procedure Button1Click(Sender: TObject);
            procedure Button3Click(Sender: TObject);
            procedure ListBox1Click(Sender: TObject);
            procedure Button2Click(Sender: TObject);
        procedure Timer1Timer(Sender: TObject);
        private
        { Private declarations }
            procedure navigate(aurl: string);
        public
        { Public declarations }
        end;var
        Form1: TForm1;implementation{$R *.dfm}
    uses
        jpeg, gifimage, StrUtils;procedure TForm1.Button1Click(Sender: TObject);
    begin
        memo1.lines.text := lowercase(http.get(edit2.text));
        button3.Click;
    end;procedure tform1.navigate(aurl: string);
    var
        afile: tfilestream;
        tmp: string;
    begin
        tmp := extractfileext(aurl);
        afile := tfilestream.create('f:\a' + tmp, fmcreate);
        http.DoRequest(hmget, aurl, nil, afile);
        afile.free;    image1.Picture.LoadFromFile('f:\a' + tmp);
    end;procedure TForm1.Button3Click(Sender: TObject);
    var
        i, j, currfrom, currto: integer;
        tmp,tmp1: string;
    begin
        listbox1.clear;
        currfrom := 0;
        repeat
            currto := 0;
            i := pos('<img src=', copy(memo1.lines.Text, currfrom,
                length(memo1.lines.text) - currfrom));
            if i <> 0 then
            begin
                currfrom := currfrom + i;
                i := pos('>', copy(memo1.Lines.text, currfrom,
                    length(memo1.lines.text) - currfrom));
                if i <> 0 then
                begin
                    currto := currfrom + i;
                    tmp := copy(memo1.Lines.Text, currfrom, currto - currfrom);
                    if pos('http://', tmp) = 0 then
                    begin
                        i := pos('src=', tmp);
                        j := 0;
                        j := pos('.jpg', tmp);
                        if j = 0 then j := pos('.gif', tmp);
                        if j = 0 then j := pos('.bmp', tmp);
                        if (i <> 0) and (j <> 0) then
                        begin
                            tmp := copy(tmp, i + 5, j + 4 - i - 5);
                            if pos('.htm',tmp)=0 then
                            begin
                                if pos('.htm',edit2.Text)<>0 then
                                begin
                                    tmp1:=reversestring(edit2.text);
                                    i:=pos('/',tmp1);
                                    tmp1:=copy(tmp1,i+1,length(tmp1)-i);
                                    tmp1:=reversestring(tmp1)+'/';
                                end
                                else
                                    tmp1:=edit2.Text;
                                listbox1.Items.add(tmp1+tmp);
                            end;
                        end;
                    end
                        else
                        begin
                            i := pos('http://', tmp);
                            j := 0;
                            j := pos('.jpg', tmp);
                            if j = 0 then j := pos('.gif', tmp);
                            if j = 0 then j := pos('.bmp', tmp);
                            if (i <> 0) and (j <> 0) then
                            begin
                                tmp := copy(tmp, i , j + 4 - i );
                                listbox1.Items.add(tmp);
                            end;                    end;
                        currfrom := currto;
                    end;
                end;
        until (currfrom = 0) or (currto = 0);
        // 超链接
        currfrom := 0;
        repeat
            currto := 0;
            i := pos('<a href=', copy(memo1.lines.Text, currfrom,
                length(memo1.lines.text) - currfrom));
            if i <> 0 then
            begin
                currfrom := currfrom + i;
                i := pos('>', copy(memo1.Lines.text, currfrom,
                    length(memo1.lines.text) - currfrom));
                if i <> 0 then
                begin
                    currto := currfrom + i;
                    tmp := copy(memo1.Lines.Text, currfrom, currto - currfrom);
                    if pos('http://', tmp) = 0 then
                    begin
                        i := pos('a href=', tmp);
                        j := 0;
                        j := pos('.jpg', tmp);
                        if j = 0 then j := pos('.gif', tmp);
                        if j = 0 then j := pos('.bmp', tmp);
                        if j = 0 then j := pos('.htm', tmp);   ///
                        if (i <> 0) and (j <> 0) then
                        begin
                            tmp := trim(copy(tmp, i + 7, j + 4 - i - 7));
                            if (copy(tmp,1,1)='"')or(copy(tmp,1,1)='''') then
                                tmp:=copy(tmp,2,length(tmp)-1);
                            if pos('.htm',tmp)=0 then
                            begin
                                tmp1:=reversestring(edit2.text);
                                i:=pos('/',tmp1);
                                tmp1:=copy(tmp1,i+1,length(tmp1)-i);
                                tmp1:=reversestring(tmp1);
                                listbox1.Items.add(tmp1+'/'+tmp);
                            end;
                        end;
                    end
                        else
                        begin
                            i := pos('http://', tmp);
                            j := 0;
                            j := pos('.jpg', tmp);
                            if j = 0 then j := pos('.gif', tmp);
                            if j = 0 then j := pos('.bmp', tmp);
                            if j = 0 then j := pos('.htm', tmp);   ///
                            if (i <> 0) and (j <> 0) then
                            begin
                                tmp := copy(tmp, i , j + 4 - i );
                                listbox1.Items.add(tmp);
                            end;                    end;
                        currfrom := currto;
                    end;
                end;
        until (currfrom = 0) or (currto = 0);
    end;procedure TForm1.ListBox1Click(Sender: TObject);
    var
        tmp:string;
    begin
        tmp:= listbox1.Items[listbox1.itemindex];
        if pos('htm',tmp)=0 then
            navigate(tmp)
        else
        begin
            edit2.Text:=tmp;
            button1.Click;
        end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    begin
        navigate(edit1.text);
    end;procedure TForm1.Timer1Timer(Sender: TObject);
    begin
        application.ProcessMessages;
    end;end.这是我以前写的一个乱七八糟的代码,但愿能帮你。
      

  2.   

    哈哈哈可怜的木石三。。
    对不起我不懂。。但关注。。
    有消息,请发一个给我。。
    [email protected]
      

  3.   

    如果大家觉得难,可以先告诉我你们知道的前几步,比如怎样得到该网页的源文件,我试过用NMHTTP去得到EDIT里的地址,但运行后只要一点按钮,总是出错,不知怎么回事。
      

  4.   

    object Form1: TForm1
      Left = 192
      Top = 107
      Width = 544
      Height = 375
      Caption = 'Form1'
      Color = clBtnFace
      Font.Charset = DEFAULT_CHARSET
      Font.Color = clWindowText
      Font.Height = -11
      Font.Name = 'MS Sans Serif'
      Font.Style = []
      OldCreateOrder = False
      WindowState = wsMaximized
      PixelsPerInch = 96
      TextHeight = 13
      object Image1: TImage
        Left = 312
        Top = 104
        Width = 145
        Height = 161
        AutoSize = True
      end
      object Button1: TButton
        Left = 552
        Top = 8
        Width = 75
        Height = 25
        Caption = 'Button1'
        TabOrder = 0
        OnClick = Button1Click
      end
      object Edit1: TEdit
        Left = 312
        Top = 40
        Width = 465
        Height = 21
        TabOrder = 1
        Text = 'http://hzect.d2g.com/deepsky/deepsky.jpg'
      end
      object Button2: TButton
        Left = 312
        Top = 64
        Width = 75
        Height = 25
        Caption = 'Button2'
        TabOrder = 2
        OnClick = Button2Click
      end
      object Panel1: TPanel
        Left = 0
        Top = 0
        Width = 305
        Height = 332
        Align = alLeft
        BorderWidth = 2
        Caption = 'Panel1'
        TabOrder = 3
        object Splitter1: TSplitter
          Left = 3
          Top = 212
          Width = 299
          Height = 2
          Cursor = crVSplit
          Align = alBottom
          ResizeStyle = rsLine
        end
        object Splitter2: TSplitter
          Left = 3
          Top = 103
          Width = 299
          Height = 2
          Cursor = crVSplit
          Align = alTop
        end
        object Memo1: TMemo
          Left = 3
          Top = 3
          Width = 299
          Height = 100
          Align = alTop
          Lines.Strings = (
            'Memo1')
          TabOrder = 0
        end
        object ListBox1: TListBox
          Left = 3
          Top = 214
          Width = 299
          Height = 115
          Align = alBottom
          ItemHeight = 13
          TabOrder = 1
          OnClick = ListBox1Click
        end
        object ListBox2: TListBox
          Left = 3
          Top = 105
          Width = 299
          Height = 107
          Align = alClient
          ItemHeight = 13
          TabOrder = 2
        end
      end
      object Button3: TButton
        Left = 632
        Top = 8
        Width = 75
        Height = 25
        Caption = 'Button3'
        TabOrder = 4
        OnClick = Button3Click
      end
      object Edit2: TEdit
        Left = 312
        Top = 8
        Width = 233
        Height = 21
        TabOrder = 5
        Text = 'http://127.0.0.1'
      end
      object Http: TIdHTTP
        MaxLineAction = maException
        ReadTimeout = 0
        AllowCookies = True
        ProxyParams.BasicAuthentication = False
        ProxyParams.ProxyPort = 0
        Request.ContentLength = 0
        Request.ContentRangeEnd = 0
        Request.ContentRangeStart = 0
        Request.ContentType = 'text/html'
        Request.Accept = 'text/html, */*'
        Request.BasicAuthentication = False
        Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)'
        HTTPOptions = [hoForceEncodeParams]
        Left = 24
        Top = 24
      end
      object IdAntiFreeze1: TIdAntiFreeze
        Left = 56
        Top = 24
      end
      object Timer1: TTimer
        Interval = 50
        OnTimer = Timer1Timer
        Left = 88
        Top = 24
      end
    end
      

  5.   

    恭喜什么呢,天天来这里,水平不见高,不如学Kingron闭关算了。老亦老亦。