onlyou13

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
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.

 

posted on 2021-08-23 19:01  onlyou13  阅读(581)  评论(0编辑  收藏  举报