已知某个网页的网址,如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分,绝不食言。
先谢谢大家了!
<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分,绝不食言。
先谢谢大家了!
解决方案 »
- 考试题目,请高手帮帮忙
- 如何将字符数组的前30个字符放入字符串中,在线等
- 在线急求:Dbgrid的问题
- SOS,用d7使用TDHTMLEdit出现的问题,请高手回答(大送分,200分)
- 很是简单的问题。送分了。请问:ctrl和z的ASCII值是多少呀,给分现在就结贴
- 没有装数据库的服务器,我要想得到它的具体现在时间,实现代码为?在程序中用一按纽备份SQL SERVER2000中的kkk数据库,代码?THANKS!
- 为什么我的报表,预览时有数据,而打出来时没有数据???
- ADO超时错误?timeout设置为很大也没用?
- 如何把integer转成string?
- 怎样在程序中判断字段的数据类型?
- 不知道有没有人知道这是哪个国家的语言文字(编程技术文章)???要是没人知道,就当是散分吧!
- 如何在程序中使用JPEG资源?我的程序有什么问题?help!
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.这是我以前写的一个乱七八糟的代码,但愿能帮你。
对不起我不懂。。但关注。。
有消息,请发一个给我。。
[email protected]
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