delphi获得webbrowser中的html文本

procedure TForm1.Button1Click(Sender: TObject);
begin
  WebBrowser1.Navigate(Edit1.Text);

end;

procedure TForm1.Button2Click(Sender: TObject);

var
  doc:olevariant;
  str:string;
begin
    doc:=WebBrowser1.Document;
    //获取元素的值
    {str:=doc.all.xx.value;
    ShowMessage(str);}

    //写入htnl
    {doc.clear;
    doc.write('<html><head></head><body><p>新的html</p><input type="hidden" value="0" id="xx" /></body></html>');
    doc.close;}

    //改变元素的值
    {doc.all.xx.value:='1';
    ShowMessage(doc.all.xx.value);}

    //获得html文本
    str:=doc.documentElement.outerHtml;
    Memo1.Text:=str;
end;

 

posted @ 2022-10-04 00:15  IT情深  阅读(100)  评论(0编辑  收藏  举报