unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, WebView2, Winapi.ActiveX, Vcl.Edge, Vcl.StdCtrls, Vcl.ExtCtrls,Winapi.ShellAPI; type TForm1 = class(TForm) EdgeBrowser1: TEdgeBrowser; Panel1: TPanel; Button2: TButton; Panel2: TPanel; procedure Button2Click(Sender: TObject); procedure EdgeBrowser1ExecuteScript(Sender: TCustomEdgeBrowser; AResult: HRESULT; const AResultObjectAsJson: string); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; ScriptResult:string; list1:TStringlist; const jsFile = ' var test=document.getElementsByTagName(''html'')[0].innerText; ' + #13#10 +' var result=null; ' + #13#10 +' //alert(test); ' + #13#10 +' Result=test;'; implementation uses Clipbrd; {$R *.dfm} function OpenURL(const URL: string): boolean; begin //ShellExecute(0, 'open', PChar(URL), nil, nil, SW_SHOWNORMAL); ShellExecute(0, 'open', PChar(URL), nil, PChar(ExtractFilePath(ParamStr(0))), SW_SHOWNORMAL);//这样写是为了指定工作目录 end; function getJavaScript(ScriptPath:string):string; var AList:TStringList; begin Alist:= TStringList.Create; Alist.LoadFromFile(ScriptPath, TEncoding.UTF8); Result:= AList.Text; AList.Free; end; procedure TForm1.Button2Click(Sender: TObject); var LAText:string; begin list1.Clear; LAText:= jsFile; edgebrowser1.ExecuteScript(LAText); end; procedure TForm1.EdgeBrowser1ExecuteScript(Sender: TCustomEdgeBrowser;AResult: HRESULT; const AResultObjectAsJson: string); var hEdit: HWND; begin ScriptResult:= AResultObjectAsJson; list1.add(ScriptResult); list1.SaveToFile('123.txt'); openurl('123.txt'); end; procedure TForm1.FormCreate(Sender: TObject); begin
end; end.