| 发表于:2007-12-18 18:58:231楼 得分:0 |
用webbrowser打开网页后,网页内的所有元素你都可以通过代码来操作, 方法是:1.根据标记名(tagname)的和元素名name来找到元素, 2.给元素赋值或是执行相关的事件. 例1: 给username文本框内填充内容: private sub webbrowser1_documentcomplete(byval pdisp as object, url as variant) dim doc dim tg set doc = webbrowser1.document for i = 0 to doc.all.length - 1 if (lcase(doc.all(i).tagname)) = "input" then if (lcase(doc.all(i).name)) = "username" then set tg = doc.all(i) tg.value=text1.text end if end if next i end sub 例2: 找到提交按钮并点击 private sub webbrowser1_documentcomplete(byval pdisp as object, url as variant) dim doc dim tg set doc = webbrowser1.document for i = 0 to doc.all.length - 1 if (lcase(doc.all(i).tagname)) = "input" then if (lcase(doc.all(i).type)) = "submit" then set tg = doc.all(i) tg.click end if end if next i end sub | | |
|