gpt4 book ai didi

delphi - 自动登录(网络浏览器)

转载 作者:行者123 更新时间:2023-12-03 15:52:24 27 4
gpt4 key购买 nike

我正在尝试登录(以执行一些日常任务)网页(www.soccerproject.com),但我无法执行此操作,因为提交按钮类是“superbutton”,它没有 click() 处理程序,或开头的 ID。我尝试执行绑定(bind)到按钮的 onClick 方法的 JavaScript,但它不起作用,所以这是我的代码,如果有人可以提供一些帮助,我将不胜感激。

procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.soccerproject.com/spnewl_index.php');
end;

procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject;
const pDisp: IDispatch; var URL: OleVariant);
var ii:integer ;
begin
if (WebBrowser1.LocationURL='http://www.soccerproject.com/spnewl_index.php') and (i<4) then inc(i);

if i=4 then begin
WebBrowser1.OleObject.Document.getElementById('login').setAttribute('value', Edit1.Text);
WebBrowser1.OleObject.Document.getElementById('password').setAttribute('value', Edit2.Text);

wait(200);
WebBrowser1.OleObject.Document.forms[0].submit();
WebBrowser1.Navigate('http://www.soccerproject.com/#');
end;
end;

我数到 4 的原因是,这是网络浏览器需要完全加载并显示网站的时间(以便能够填写文本)。此外,wait() 函数仅等待 200 毫秒(只是为了确定)。提前致谢

最佳答案

您的代码中存在许多问题。计数和等待过程实际上是没有必要的。提供的代码向您展示了如何检测页面何时完全加载。不需要第二次调用 Navigate,因为提交表单将导致浏览器加载主页。此代码已在提供的网站上进行了测试并且有效:)

unit u_frm_main;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, OleCtrls, SHDocVw, MsHtml;

type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
procedure WebBrowser1DocumentComplete(ASender: TObject; const pDisp: IDispatch; var URL: OleVariant);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
WebBrowser1.Navigate('http://www.soccerproject.com/spnewl_index.php');
end;

procedure TForm1.WebBrowser1DocumentComplete(ASender: TObject; const pDisp: IDispatch; var URL: OleVariant);

var
CurrentBrowser: IWebBrowser2;
TopBrowser: IWebBrowser2;
Document: OleVariant;
Doc3 : IHTMLDocument3;
Frm : IHtmlFormElement;

begin
CurrentBrowser := pDisp as IWebBrowser2;
TopBrowser := (ASender as TWebbrowser).DefaultInterface;
if Assigned(CurrentBrowser) and Assigned(TopBrowser) then
begin
if CurrentBrowser = TopBrowser then
begin
Doc3 := CurrentBrowser.Document as IHTMLDocument3;
Webbrowser1.OnDocumentComplete := nil; // remove handler to avoid reentrance
Doc3.getElementById('login').setAttribute('value', 'SO17999392', 0);
Doc3.getElementById('password').setAttribute('value', 'XXXXX', 0);
Frm := Doc3.getElementById('indexform') as IHtmlFormElement;
if Assigned(Frm) then
Frm.submit;
end;
end;
end;

end.

关于delphi - 自动登录(网络浏览器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17999392/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com