Delphi: How to get information and manipulate Html in a TStringList?

2

Working with TWebBrowser you can interact with elements easily, get fields, set values.

Example:

webBrowser.OleObject.Document.GetElementByID('name').setAttribute('attribute', 'value');

My question may be unrealistic, but does anyone know how to get the tags, perhaps even some information, from an Html code contained in a TStrings , for example, in a more fluid way?

Giving an example to get clearer what I want:
Let's say I have received the html from a page and I want to get the html code from some tags, get some values, maybe set some to then return, etc.

    
asked by anonymous 08.08.2014 / 01:47

1 answer

2

One easy way I found to do this was this:

var
  doc: variant;
  element: variant;
begin
  doc := coHTMLDocument.Create as IHTMLDocument2;
  doc.write(html);   
  doc.Close;
  ...
  element := doc.getElementById('elementId');
  ...
  element.getAttribute('value', 0);
end;

Based on Windows COM components.

    
11.08.2014 / 19:01