Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2007.09.09;
Скачать: CL | DM;

Вниз

Как вытянуть из html-файла список всех ссылок и картинок   Найти похожие ветки 

 
K@KTUS ©   (2007-01-14 22:16) [0]

Пожалуйста, подскажите как вытянуть из html-файла список всех ссылок и картинок не используя WebBrowser.


 
Eraser ©   (2007-01-15 00:53) [1]

> [0] K@KTUS ©   (14.01.07 22:16)

с пом. регулярных выражений.


 
easy ©   (2007-01-15 12:23) [2]

uses
 ActiveX, ComObj, MSHTML;

procedure TForm1.Button1Click(Sender: TObject);
var
 vHttp: OleVariant;
 vContext: OleVariant;
 vDocument: IHTMLDocument2;
 vHtml: String;
 vColl:IHTMLElementCollection;
 i:integer;
begin
 Screen.Cursor:=crHourGlass;
 Button1.Enabled:=false;
 vHttp := CreateOleObject("Microsoft.XMLHTTP"); { Requires IE5 }
 vHttp.Open("GET", "http://www.google.ru/", False, EmptyParam, EmptyParam);
 vHttp.Send("");
 vHtml := vHttp.responseText;
 vDocument := CoHTMLDocument.Create as IHTMLDocument2;
 vContext := VarArrayCreate([0, 0], varVariant);
 vContext[0] := vHtml;
 vDocument.Write(PSafeArray(TVarData(vContext).VArray));
 vDocument.Close;
 vDocument.all.tags("A").QueryInterface(IHTMLElementCollection,vColl);
 ListBox1.Clear;
 for i:=0 to vColl.length-1 do begin
    ListBox1.Items.Add((vColl.item(i,EmptyParam) as IHTMLElement).innerText);
 end;
 Button1.Enabled:=true;
 Screen.Cursor:=crDefault;
end;


 
K@KTUS ©   (2007-01-15 23:44) [3]

Что-то этот вариант не особо хочет работать с некоторыми сайтами. И мне нужно, чтобы была сама ссылка типа http://....,а не текст под которым она скрывается


 
easy ©   (2007-01-16 13:47) [4]

ListBox1.Items.Add((vColl.item(i,EmptyParam) as IHTMLElement).href);


 
K@KTUS ©   (2007-01-16 23:03) [5]


> ListBox1.Items.Add((vColl.item(i,EmptyParam) as IHTMLElement).href);

href не работает (Undeclared identifer: "href")


 
K@KTUS ©   (2007-01-16 23:57) [6]


> Eraser ©   (15.01.07 00:53) [1]
> с пом. регулярных выражений.


А подробнее можно??


 
easy ©   (2007-01-17 11:04) [7]

извиняюсь, не
(vColl.item(i,EmptyParam) as IHTMLElement).href
а
(vColl.item(i,EmptyParam) as IHTMLAnchorElement).href

>> Eraser ©   (15.01.07 00:53) [1]
>> с пом. регулярных выражений.
>
>
> А подробнее можно??

uses RegExpr;

procedure GetLinks(const Text:string; Lines:TStrings);
const
 expr = "(?is)(<a.+?href=(\"|\s|)(.+?)(\"|\s|>).+?>)";
begin
with TRegExpr.Create do
 try
   Expression := expr;
   if Exec(Text) then begin
     repeat
       Lines.Add(Match[3]);
     until not ExecNext;
   end;
 finally
   Free;
 end;
end;


TRegExpr тут -
http://www.regexpstudio.com/RU/TRegExpr/TRegExpr.html


 
K@KTUS ©   (2007-01-17 23:52) [8]

Спасибо БОЛЬШОЕ. Сегодня попробую...



Страницы: 1 вся ветка

Текущий архив: 2007.09.09;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.043 c
2-1186858488
TStas
2007-08-11 22:54
2007.09.09
Описание ф-ции InternetGetConnectedState


15-1187082510
Kostafey
2007-08-14 13:08
2007.09.09
Всякий раз при запуске Win стало появляться это сообщение


2-1187415122
actis
2007-08-18 09:32
2007.09.09
Как описать выделение мышью на рисунке?


15-1185992894
Курдль
2007-08-01 22:28
2007.09.09
Кризис меломана или "что слушать?"


2-1187575002
Alex_AA
2007-08-20 05:56
2007.09.09
Как открыть файл .doc, на который установлен пароль?