C#經過COM組件操做IE瀏覽器(二):使用IHTMLDocument3完成登陸

第一章介紹瞭如何打開網站,這一章介紹一下使用IHTMLDocument3完成登陸博客園,如下爲代碼:函數

  1. SHDocVw.InternetExplorer oBrowser = new SHDocVw.InternetExplorer();
  2. ;
  3. object objTargetFrameName = "_self";
  4. object objPostData = "";
  5. object objHeaders = "";
  6. oBrowser.Visible = true;
  7. oBrowser.Navigate("https://passport.cnblogs.com/user/signin", ref objFlags, ref objTargetFrameName, ref objPostData, ref objHeaders);
  8. while (true)
  9. {
  10. Thread.Sleep();
  11. if (oBrowser.ReadyState == SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
  12. break;
  13. }
  14. IHTMLDocument3 doc3 = (IHTMLDocument3)oBrowser.Document;
  15. IHTMLInputElement txtUserName = (IHTMLInputElement)doc3.getElementById("input1");
  16. txtUserName.value = "你的用戶名";
  17. IHTMLInputElement txtPassWord = (IHTMLInputElement)doc3.getElementById("input2");
  18. txtPassWord.value = "你的密碼";
  19. doc3.getElementById("signin").click();

使用以上代碼就成功登陸到博客園了,下面整理一下IHTMLDocument3以及相關的一些方法和屬性:網站

IHTMLDocument3 方法 說明
attachEvent

從IE11開始,使用addEventListener。將指定的函數綁定到一個事件,以便每當事件在對象上觸發時,該函數被調用。spa

createDocumentFragment 建立一個新文檔並返回一個指向新建立的文檔的指針。
createTextNode

從指定的值建立一個文本字符串。指針

detachEvent 從事件中取消綁定指定的功能,以使該功能在事件觸發時中止接收通知。
getElementById 返回對具備指定值id屬性的第一個對象的引用。
getElementsByName 根據name屬性的值獲取對象集合。
getElementsByTagName 根據指定的元素名稱檢索對象的集合。
recalc 此元素已過期,再也不使用。從新計算當前文檔中的全部動態屬性。
releaseCapture

從當前文檔中的對象中刪除鼠標捕獲。對象

IHTMLDocument3屬性與事件 說明
baseUrl  
dir 設置或檢索指示對象的讀取順序的值。
documentElement 獲取對文檔根節點的引用。
enableDownload 設置啓用下載
inheritStyleSheets 暫未說明
onbeforeeditfocus 設置焦點以前
oncellchange 當數據來源發生變化時
oncontextmenu 當按下鼠標右鍵出現菜單或經過鍵盤觸發頁面菜單時
onpropertychange 改變屬性時
onrowsdelete 當前數據記錄被刪除時
onrowsinserted 當前數據源將要插入新數據時
uniqueID 檢索對象的自動生成的惟一標識符。
onstop 中止或離開時
ondatasetchanged 數據源發生變化時
ondatasetcomplete 當數據接收完成時
ondataavailable 當數據源的所有有效數據讀取完畢時

這一章介紹了IHTMLDocument3,而且使用IHTMLDocument3完成了登陸,下一章介紹IHTMLDocument2以及用法.blog

相關文章
相關標籤/搜索