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

Asked

Viewed 1,578 times

2

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

Example:

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

My question may be quite unreal, but someone knows a way to get the tags, maybe even work some information, from an HTML code contained in a TStrings, for example more fluoride?

Giving an example to make clearer what I wish:
Let’s say I 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.

  • 1

    HTML is a kind of markup document, such as XML. As such, you can browse your Nodes as an XML document. You can create/edit html documents using Ixmldocument with a little effort

1 answer

2

An easy way I found to do it was like 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 then on Windows COM components.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.