![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Зкачка [D7, WinXP]
NLO © (2004-08-17 17:41:00)Здравствуйте уважаемые мастера................
У меня возникли такие вопросы:
1.Как можно получить адреса всех ссылок на странице
P.S.Как это делает опера.
2.Как можно сохранить страничку с картинками.
Заранее большое спасибо.
VMcL (2004-08-17 18:04:00) [1]>> NLO © (17.08.04 17:41)
1.
1.a. Опера это делает с помощью собственного HTML-парсера, AFAIK.
1.b. http://www.delphimaster.ru/cgi-bin/forum.pl?id=1091401082&n=4
2. http://www.delphimaster.ru/cgi-bin/forum.pl?id=1087974793&n=4
P.S. Ты это, с тэгами поосторожнее - в глазах аж зарябило...
Rouse_ (2004-08-17 18:04:00) [2]1. http://www.swissdelphicenter.ch/en/showcode.php?id=479
2. В качестве сырого примера:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, SHDocVw, ActiveX, MSHTML_TLB, StdCtrls, UrlMon;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
procedure SaveAllImages;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
WebBrowser1.Navigate('www.ya.ru');
end;
function DownloadFile(SourceFile, DestFile: string): Boolean;
begin
try
Result := UrlDownloadToFile(nil, PChar(SourceFile), PChar(DestFile), 0,
nil) = 0;
except
Result := False;
end;
end;
procedure TForm1.SaveAllImages;
var
k, p: Integer;
Source, dest, ext: string;
begin
for k := 0 to WebBrowser1.OleObject.Document.Images.Length - 1 do
begin
Source := WebBrowser1.OleObject.Document.Images.Item(k).Src;
p := LastDelimiter('.', Source);
ext := UpperCase(Copy(Source, p + 1, Length(Source)));
if (ext = 'GIF') or (ext = 'JPG') then
begin
p := LastDelimiter('/', Source);
dest := 'C:\' + Copy(Source, p + 1, Length(Source));
DownloadFile(Source, dest);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
HTMLDocument: IHTMLDocument2;
PersistFile: IPersistFile;
begin
SaveAllImages;
HTMLDocument := WebBrowser1.Document as IHTMLDocument2;
PersistFile := HTMLDocument as IPersistFile;
PersistFile.Save(StringToOleStr('c:\SavedFile.html'), System.True);
end;
end.
Пример не доработанный, чтобы было нормально, желательно синхронизировать ссылки на картинки и их размещение на диске...