小白求助网页抓取图片后浏览问题
想做一个从网站源代码提取图片地址,然后进行浏览的软件;可是不知怎么实现上一张、下一张的效果,具体代码如下:unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP, ExtCtrls, GIFImage;
const
num=35;
type
TForm1 = class(TForm)
IdHTTP1: TIdHTTP;
Image1: TImage;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
IMS:TMemoryStream;
i,j:integer;
k:integer=35;//一共提取了35张图片地址
tmp,url:String;
Gif: TGIFImage;
function SplitPicUrl(LeftStr,RightStr,Data: string):TStringList;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
IdHTTP1:=TIdHTTP.Create(nil);
tmp:=IdHTTP1.Get('http://www.');
url:=SplitPicUrl('<option value="','" selected="selected">',tmp)[k];//读取第k+1个图片的地址并写入url中
IMS:=TMemoryStream.Create;
IdHTTP1.Get(url,IMS);
Image1.Picture.Assign(nil);
Gif:= TGIFImage.Create;
IMS.Position:=0;
Gif.LoadFromStream(IMS);
Image1.Picture.Assign(Gif);
IMS.Free;
Gif.Free;
IdHTTP1.Free;
end;
function SplitPicUrl(LeftStr,RightStr,Data: string):TStringList;//将Data中LeftStr与RightStr之间的字符全部截取出来
var
i,j,k: integer;
tmp: string;
begin
result := TStringList.Create;
for k:=0 to 35 do//提取了35个图片地址
begin
i:=pos(LeftStr, Data);
j:=pos(RightStr,Data);
tmp:=copy(Data, i + Length(LeftStr), j - i- Length(LeftStr));
result.Add(tmp);
Delete(Data, 1, j - 1 + Length(RightStr));
end;
end;
end.
程序可以显示出网站最新的图片,但想添加两个按钮实现上一张、下一张,就捉急了!小白一枚,网上各种搜也找不到解决,只能寄希望于各位大神了!!拜谢!