|
|
Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
|
Опции темы | Поиск в этой теме | Опции просмотра |
#1
|
||||
|
||||
Вывод содержания из HTML
Содержание HTML:
Код:
... <dl class="tb-prop tb-clearfix"> <dt>Цвет товара</dt> <dd> <ul data-property="Цвет" class="tb-clearfix J_TSaleProp tb-img "> <li data-value="1627207:28332" title="Чёрный" class="tb-txt"><a href="#" ><span>Чёрный</span></a></li> <li data-value="1627207:3232483" title="Вишнёвый" class="tb-txt"><a href="#" ><span>Вишнёвый</span></a></li> <li data-value="1627207:3232484" title="Белый" class="tb-txt"><a href="#" ><span>Белый</span></a></li> <li data-value="1627207:90554" title="Жёлтый" class="tb-txt"><a href="#" ><span>Жёлтый</span></a></li></ul> </dd> </dl> ... <dl class="tb-prop tb-clearfix"> <dt>Размер товара</dt> <dd> <ul data-property="Размер" class="tb-clearfix J_TSaleProp "> <li data-value="1630696:6536025"><a href="#"><span>XL</span></a></li> <li data-value="1630696:3266779"><a href="#"><span>XXL</span></a></li> <li data-value="1630696:3266781"><a href="#"><span>XXXL</span></a></li> </ul> </dd> </dl> ... Например: ComboBox1(Цвета) и ComboBox2(Размер) Как можно определить содержание <ul> по свойствам data-property="Цвет" и data-property="Размер", так как наверху и внизу кода в HTML есть множество <ul> с разными data-property="..."... |
#2
|
||||
|
||||
Пробовал вот так:
Код:
var i,n1: integer; o1,ot1: OleVariant; begin ComboBox1.Clear; o1:=WebBrowser1.OleObject.Document.getElementsByTagName('ul').item(0); ot1:=o1.getElementsByTagName('li'); n1:=ot1.Length; if n1>0 then begin for i:=0 to n1-1 do begin self.ComboBox1.Items.Add(ot1.item(i).InnerText); ComboBox1.ItemIndex := 0; end; end; end; Но тут никак не получается получить содержание <ul> с помощью свойства data-property="Цвет" |
#3
|
||||
|
||||
ну так проверяй значение атрибута data-property
Пишу программы за еду. __________________ |
#4
|
||||
|
||||
Цитата:
П,С, я новичок в d+html Последний раз редактировалось arxlex, 04.11.2011 в 20:38. |
#5
|
||||
|
||||
Код:
uses MSHTML, type TForm1 = class(TForm) WebBrowser1: TWebBrowser; Memo1: TMemo; Memo2: TMemo; procedure FormCreate(Sender: TObject); procedure TForm1.FormCreate(Sender: TObject); var document: OleVariant; HTMLDocument: IHTMLDocument3; HTMLElementCollection: IHTMLElementCollection; i: Integer; HTMLElement: IHTMLElement; HTMLElementCollection2: IHTMLElementCollection; j: Integer; begin Memo1.Lines.LoadFromFile('Project1.htm'); WebBrowser1.Navigate('about:blank'); while WebBrowser1.ReadyState<READYSTATE_INTERACTIVE do Application.ProcessMessages; document:=WebBrowser1.Document; document.clear; document.open; document.write(Memo1.Text); document.close; HTMLDocument:=WebBrowser1.Document as IHTMLDocument3; HTMLElementCollection:=HTMLDocument.getElementsByTagName('ul'); for i:=0 to HTMLElementCollection.length-1 do begin HTMLElement:=HTMLElementCollection.item(i, 0) as IHTMLElement; Memo2.Lines.Add('--'+HTMLElement.getAttribute('data-property', 0)+'--'); HTMLElementCollection2:=HTMLElement.children as IHTMLElementCollection; for j:=0 to HTMLElementCollection2.length-1 do Memo2.Lines.Add((HTMLElementCollection2.item(j, 0) as IHTMLElement).innerText); end; end; http://data.cod.ru/130989 http://msdn.microsoft.com/en-us/libr...(v=VS.85).aspx Пишу программы за еду. __________________ |
#6
|
||||
|
||||
Цитата:
|
#7
|
||||
|
||||
еще, один вопросик. как вытащить значение из аттрибута data-property? например как сделать так чтобы каждые значения атрибутов в коде html нашли свое место в отдельный combobox-ах? например цвет(combobox1), размер(combobox2) и тд.
Последний раз редактировалось arxlex, 06.11.2011 в 13:42. |
#8
|
||||
|
||||
Код:
type TForm1 = class(TForm) WebBrowser1: TWebBrowser; Memo1: TMemo; Memo2: TMemo; ComboBox1: TComboBox; ComboBox2: TComboBox; procedure FormCreate(Sender: TObject); procedure TForm1.FormCreate(Sender: TObject); var document: OleVariant; HTMLDocument: IHTMLDocument3; HTMLElementCollection: IHTMLElementCollection; i: Integer; HTMLElement: IHTMLElement; HTMLElementCollection2: IHTMLElementCollection; j: Integer; AComboBox: TComboBox; begin Memo1.Lines.LoadFromFile('Project1.htm'); WebBrowser1.Navigate('about:blank'); while WebBrowser1.ReadyState<READYSTATE_INTERACTIVE do Application.ProcessMessages; document:=WebBrowser1.Document; document.clear; document.open; document.write(Memo1.Text); document.close; HTMLDocument:=WebBrowser1.Document as IHTMLDocument3; HTMLElementCollection:=HTMLDocument.getElementsByTagName('ul'); for i:=0 to HTMLElementCollection.length-1 do begin HTMLElement:=HTMLElementCollection.item(i, 0) as IHTMLElement; Memo2.Lines.Add('--'+HTMLElement.getAttribute('data-property', 0)+'--'); if HTMLElement.getAttribute('data-property', 0)='Цвет' then AComboBox:=ComboBox1 else if HTMLElement.getAttribute('data-property', 0)='Размер' then AComboBox:=ComboBox2 else AComboBox:=nil; HTMLElementCollection2:=HTMLElement.children as IHTMLElementCollection; for j:=0 to HTMLElementCollection2.length-1 do begin if AComboBox<>nil then AComboBox.Items.Add((HTMLElementCollection2.item(j, 0) as IHTMLElement).innerText); Memo2.Lines.Add((HTMLElementCollection2.item(j, 0) as IHTMLElement).innerText); end; end; end; Пишу программы за еду. __________________ |
#9
|
||||
|
||||
В ходе процесса я заметил что значения 'data-property' меняется, но не меняется сам класс:
Код:
<ul data-property="Цвет" class="tb-clearfix J_TSaleProp tb-img "> Я попробывал сделать так, но не получилось... Код:
if HTMLElement.getAttribute('class', 0)='tb-clearfix J_TSaleProp tb-img ' then AComboBox:=ComboBox1 |Mess With The Best Die Like The Rest| |
#10
|
|||
|
|||
есть более понятная обёртка над этим ole - Watin, но она .net, и документацию там читать/смотреть всеравно придётся
|
#11
|
||||
|
||||
Цитата:
|Mess With The Best Die Like The Rest| |
#12
|
||||
|
||||
Цитата:
Все я разобрался сам Нужно было просто поменять "class" на "className". NumLock спасибо за ссылки Цитата:
|Mess With The Best Die Like The Rest| |