全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:3958
推到 Plurk!
推到 Facebook!

CppWebBrowser的難題-自動選取ComboBox與自動按下submit鍵

答題得分者是:RedSnow
herbertl
一般會員


發表:5
回覆:4
積分:1
註冊:2005-09-27

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-11-02 00:30:19 IP:60.248.xxx.xxx 未訂閱
小弟最近在寫從網路擷取資料的程式,也爬了非常多的文,但現在有兩個難題一直無法解就是使用CppWebBrowser來自動選取ComboBox與自動按下submit鍵,小弟所碰到的網頁如下: http://mops.tse.com.tw/server-java/t13sa150_otc?step=0 網頁內有兩個frame,內容已經可以抓了,但一直無法在第一個frame選取ComboBox與自動按下submit鍵,小弟爬過以下的文章: http://delphi.ktop.com.tw/topic.php?topic_id=32776 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=18695 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=35496 最大的問題在C Builder中找不到"GetElementByID"這個method,重要的程式by Delphi如下 Docs :=WebBrowser1.Document; Edits :=Docs.GetElementByID('CustIDTmp'); 希望有高人指點如何用C Builder的CppWebBrowse在這個網頁自動選取ComboBox與自動按下submit鍵,感恩!
RedSnow
版主


發表:79
回覆:1322
積分:845
註冊:2003-12-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-11-02 11:01:07 IP:59.115.xxx.xxx 未訂閱
herbertl 您好:
引言:最大的問題在C Builder中找不到"GetElementByID"這個method,重要的程式by Delphi如下 Docs :=WebBrowser1.Document; Edits :=Docs.GetElementByID('CustIDTmp');
看看下列方式可否達到您想要的動作?
Variant doc = CppWebBrowser1->Document;    Variant combo = doc.OleFunction("getElementById","bcode");
combo.OlePropertySet("value", "04");
上方的範例是將名為 bcode 的 ComboBox 選擇項目設定成內含值為 "04" 的項目,也就是設定成 "紡織纖維" 項目,您試試看吧。 7 天天敲鍵盤 v 時時按滑鼠 8
herbertl
一般會員


發表:5
回覆:4
積分:1
註冊:2005-09-27

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-11-02 18:45:29 IP:210.243.xxx.xxx 未訂閱
感謝RedSnow ! 小弟已經解決問題了!順便將參考的link與部分的原始碼上傳,以供其他人參考    Link: http://delphi.ktop.com.tw/topic.php?topic_id=55441    Source Code:
 
 Variant vFrame,vFrames,vFrameDocument,combo;
 Variant allbuttons,eachbutton;
 int buttoncount;      Variant vDocument = CppWebBrowser1->ControlInterface->Document;      if (((IDispatch *)vDocument) != NULL)
    {
     vFrames = vDocument.OlePropertyGet("Frames");          if(vFrames.OlePropertyGet("Length") >= 2)
       {
        vFrame = vFrames.OleFunction("Item",0);
        vFrameDocument = vFrame.OlePropertyGet("Document");            if (((IDispatch *)vFrameDocument) != NULL)
           {
            combo = vFrameDocument.OleFunction("getElementById","bcode");
            combo.OlePropertySet("value", "04");                allbuttons = vFrameDocument.OleFunction("getElementsByTagName","input"); //取得所有tag是input的集合
            buttoncount = allbuttons.OlePropertyGet("length"); //取得集合的數量
            for (int i=0;i < buttoncount; i   )
                {
                 eachbutton = allbuttons.OleFunction("item",i); //依序取得每一個input                     if (eachbutton.OlePropertyGet("value") == AnsiString("查 詢")) //判斷value的文字
                    {
                     eachbutton.OleFunction("click"); //按下按鈕
                     break; //記得離開for迴圈
                    }
                }
           }
       }
    }
</pre>
還有小弟post上來的原始碼怪怪的,有沒有人可以指點一下怎麼更正
更正好了,感恩~    發表人 - herbertl 於 2005/11/02  18:56:31    發表人 - herbertl 於 2005/11/02  18:59:05    發表人 - herbertl 於 2005/11/02  23:08:53
        
RedSnow
版主


發表:79
回覆:1322
積分:845
註冊:2003-12-15

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-11-02 20:19:22 IP:61.230.xxx.xxx 未訂閱
herbertl 您好:    張貼程式碼的方式可以參考下列連結頁面內的說明: 【公告】程式碼張貼規則與方法 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=57538 【公告】重申版規與作業問題說明 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=58991 7 天天敲鍵盤 v 時時按滑鼠 8
系統時間:2024-04-24 9:36:21
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!