for example, I have html following:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<div>
<p id="test">test paragraph</p>
</div>
</body>
</html>
and parse with pascal:
procedure TForm1.FormCreate(Sender: TObject);
var
doc: THTMLDocument;
PElement: TDOMElement;
begin
ReadHTMLFile(doc, GetCurrentDir + '\index.html');
PElement := doc.GetElementById('test'); // PElement is always nil
end;
But the PElement is always nil, I cannot get element by id, But if I using doc.GetElementsByTagName will works:
procedure TForm1.FormCreate(Sender: TObject);
var
doc: THTMLDocument;
InnerText: DOMString;
PElement: TDOMNodeList;
begin
ReadHTMLFile(doc, GetCurrentDir + '\index.html');
PElement := doc.GetElementsByTagName('p');
InnerText := PElement[0].TextContent;
DebugLn(InnerText); // It print 'test paragraph' to console, it mean works
end;