0

I want to get information from webpage to do it I need to list all columns and rows inside html document

I can get access to html elements by ID but how to get access to all rows and columns inside html code to get html code for each cell?

function GetElementById(const Doc: IDispatch; const Id: string;memo:tmemo): IDispatch;
var
  Document: IHTMLDocument2;     // IHTMLDocument2 interface of Doc
  Body: IHTMLElement2;          // document body element
  Tags: IHTMLElementCollection; // all tags in document body
  Tag: IHTMLElement;            // a tag in document body
  I: Integer;                   // loops thru tags in document body
begin
  Result := nil;

  // Check for valid document: require IHTMLDocument2 interface to it
  if not Supports(Doc, IHTMLDocument2, Document) then
    raise Exception.Create('Invalid HTML document');
  // Check for valid body element: require IHTMLElement2 interface to it
  if not Supports(Document.body, IHTMLElement2, Body) then
    raise Exception.Create('Can''t find <body> element');
  // Get all tags in body element ('*' => any tag name)
  Tags := Body.getElementsByTagName('*');

  // Scan through all tags in body
  for I := 0 to Pred(Tags.length) do
  begin
    // Get reference to a tag
    Tag := Tags.item(I, EmptyParam) as IHTMLElement;

    // Check tag's id and return it if id matches
    if AnsiSameText(Tag.id, Id) then
    begin
      memo.lines.add(Tag.id);
      memo.Lines.Add(tag.outerHTML);
      Result := Tag;
      Break;
    end;
  end;
end;
whosrdaddy
  • 11,720
  • 4
  • 50
  • 99
  • 1
    we need a bit more context here, what are you trying to do? maybe add some html to highlight the problem? – whosrdaddy Oct 13 '17 at 15:20
  • ` how to get access to all rows and columns?` Do you mean the rows and columns of any table(s) the page contains, or what? – MartynA Oct 14 '17 at 16:26

0 Answers0