uses : MSHTML_TLB wb: Twebbrowser
////////////////////////////////////////////////////////
// 功能:模拟按下网页中的某一个按钮,根据Type和Name判断
// 参数:
// ButtonName: 按钮名
// 日期:2001-12-31
////////////////////////////////////////////////////////
procedure TfrmMain.PressButton(ButtonName: String);
var
  spDisp: IDispatch;
  j: integer;
  IE1: IWebBrowser2;
  IDoc1: IHTMLDocument2;
  iELC  : IHTMLElementCollection ;
  sn,Bt : string;
  HtmlInputEle : IHTMLInputElement;
  itemSec: IHTMLElement;
begin
    ButtonName := UpperCase(ButtonName);
    spdisp := wb.Application;
    if spDisp = nil then exit;
    spDisp.QueryInterface( iWebBrowser2, IE1);
    if IE1 <> nil then
    begin
      IE1.Document.QueryInterface(IHTMLDocument2,iDoc1);
      if iDoc1 <> nil then
      begin
        ielc:=idoc1.Get_all;
        for j:=0 to ielc.length-1 do
        begin
          Application.ProcessMessages;
          spDisp := ielc.item(J, 0);
          spDisp.QueryInterface(IHTMLElement ,itemSec);
          if (SUCCEEDED(spDisp.QueryInterface(IHTMLInputElement ,HtmlInputEle))) and
             (SUCCEEDED(spDisp.QueryInterface(IHTMLElement ,itemSec))) then
          with HtmlInputEle do
          begin
            sn := HtmlInputEle.name;
            sn := UpperCase(sn);
            Bt := HtmlInputEle.Get_type_;
            Bt := UpperCase(Bt);
//            showmessage(sn + '  ' + bt);
            if (StrComp(PChar(sn),PChar(ButtonName))=0) and
                (StrComp(PChar(Bt),'SUBMIT')=0) then
              begin
                itemsec.click;
                break;
              end;
          end;
        end;  //END FOR
      end;
    end;
end;

解决方案 »

  1.   

    sorry,没完全理解,估计这样可以:先手动登录,在登录时截下BeforeNavigate2事件中的数据:PostData,Headers,下次再用Navigate()将这两个数据传出去就行了,但有的网页要多次POST数据,可能要按顺序记录下来再使用才可以。
      

  2.   

    那没有必要用这个,用fastnet的http组件就行了    
      

  3.   

    俄,谢谢,我去试一试。不过它的“连接按钮”是图片:
    span class="form"><input type="image" name="ok" value="确定" src="images/go.gif" width="37" height="10"></span>
    我去试一试,不过这样我还要网页里面填数据,Post方法是比较麻烦。 Post数据包的格式是什么?能不能自己生成包的格式,然后发送请求?
      

  4.   

    看来实现方法还不少,不知道TIdHttp控件用起来是不是更方便?
      

  5.   

    再来:
    ////////////////////////////////////////////////////////
    // 功能:向网页中填写内容
    // 参数:
    // 日期:2001-12-31
    ////////////////////////////////////////////////////////
    procedure TfrmMain.PutData;
    var
      spDisp: IDispatch;
      j: integer;
      IE1: IWebBrowser2;
      IDoc1: IHTMLDocument2;
      iELC  : IHTMLElementCollection ;
      S2,sn : string;
      HtmlInputEle : IHTMLInputElement;
    //  HtmlSelEle  : IHTMLSelectElement;
    begin
        spdisp := wb.Application;
        if spDisp = nil then exit;
        spDisp.QueryInterface( iWebBrowser2, IE1 );
        if IE1 <> nil then
        begin
          IE1.Document.QueryInterface(IHTMLDocument2,iDoc1);
          if iDoc1 <> nil then
          begin
            ielc:=idoc1.Get_all;
            for j:=0 to ielc.length-1 do
            begin
              Application.ProcessMessages;
              spDisp := ielc.item(J, 0);
              if SUCCEEDED(spDisp.QueryInterface(IHTMLInputElement ,HtmlInputEle))then
              with HtmlInputEle do
              begin
                S2:=Type_;
                S2:=UpperCase(S2);
                if StrComp(PChar(S2),'TEXT')=0 then
                  begin
                    sn := name;
                    sn := UpperCase(sn);
                    if StrComp(PChar(sn),'CUSTCODE')=0 then value :='12345656';
                  end;
                if StrComp(PChar(S2),'PASSWORD')=0 then
                  begin
                    sn := name;
                    sn := UpperCase(sn);
                    if StrComp(PChar(sn),'CUSTPASS')=0 then value :='1234';
                  end;
              end;
            end;  //END FOR
          end;
        end;
    end;
      

  6.   

    不好意思,冒昧问一句:MSHTML_TLB到哪里去找?我没有,没法编译
      

  7.   

    找到了:http://community.borland.com/article/0,1410,26574,00.html