用delphi提交表格

时间:2014-04-05 12:15:27

标签: forms delphi browser submit

我尝试用Delphi提交预填表格 - 但似乎不可能。我预先填写的网站是:Lufthansa.com advanced search page

我无法点击“查找航班”按钮:

<button type="submit" class="processBtn">
  <span class="stageButtonLeft">&nbsp;</span>
  <span class="stageButtonRight">Find flights</span>
</button>

或提交表格:

<form method="post" autocomplete="off" 
  action="/booking/validation/flightavailability" 
  id="advancedSearchFlights">

我尝试了几件事:

ie.OleObject.Document.forms.item(2).elements.item(0).click;

ie.OleObject.Document.forms.item(2).elements.item('submit').click;

 Frm := Doc3.getElementById('advancedSearchFlights') as IHtmlFormElement;
 if Assigned(Frm) then
  Frm.submit;

什么都没发生。如何通过Delphi提交此表单?

1 个答案:

答案 0 :(得分:0)

您可以使用chrome调试表单事件以获取正确的参数,并使用Indy发布表单。

像这样......

var
  objHttp: TIdHttp;
  objPostResponse: TMemoryStream;
  objParamPost: TStringList;
begin
    objHttp := TIdHTTP.Create(nil);
    try
        objHttp.HandleRedirects := True;
        objHttp.AllowCookies := True;
        objHttp.Get('http://www....');
        objPostResponse := TMemoryStream.Create;
        try
            objParametrosPost := TStringList.Create;
            try
                objParamPost.Add('hdnStatus=ativo');                    
                objHttp.Post('http://www...', objParamPost, objPostResponse);
            finally
                FreeAndNil(objParamPost);
            end;
            // do whatever you want with the response
        finally
          FreeAndNil(objPostResponse);
        end;
    finally
        FreeAndNil(objHttp);
    end;
end;