Sub Main() Dim ie As Object Set ie = CreateObject("InternetExplorer.Application") ie.Visible = True End Sub
ie.Navigate "http://www.baidu.com"
While ie.ReadyState <> 4 Or ie.Busy = True DoEvents Wend
<input type="text" name="wd" id="kw1" maxlength="100" style="width:474px;" autocomplete="off">
ie.Document.getElementById("kw1").value = "hellow world"
<input type="submit" value="百度一下" id="su1" class="btn" onmousedown="this.className=‘btn btn_h‘" onmouseout="this.className=‘btn‘">
ie.Document.getElementById("su1").click
ie.document.all ie.document.body ie.document.getElementsByName ie.document.getElementsByTagName
<html> <frameset cols="25%,50%,25%"> <frame src="frame_a.htm" /> <frame src="frame_b.htm" /> <frame src="frame_c.htm" /> </frameset> </html>
Dim objFRAME As FramesCollection Set objFRAME = ie.document.frames Dim HW As HTMLWindow2 Set HW = objFRAME(1) HW.document.all ...
Dim objShell As Object Dim objIE As Object Dim n As Integer Set objShell = CreateObject("Shell.Application") For n = objShell.Windows.Count To 1 Step -1 Set objIE = objShell.Windows(n - 1) If objIE Is Nothing Then Exit For End If If Right(UCase(objIE.FullName), 12) = "IEXPLORE.EXE" Then Debug.Print objIE.document.URL ‘测试,输入URL If objIE.document.URL = "http://www.baidu.com" Then ‘看看是不是你要的页面 ‘找到你要操作的页面了,开始处理 End If End If Next Set objShell = Nothing
SHDocVw.InternetExplorer ie = new SHDocVw.InternetExplorer(); ie.Navigate("http://www.baidu.com"); ie.Visible = true;
shtml.HTMLDocument doc = ie.Document;
doc.getElementById("kw1").value = "hellow world";
doc.getElementById("su1").click();
public static SHDocVw.InternetExplorer getInternetExploer(string url) { var shell = new Shell32.Shell(); var windows = (SHDocVw.IShellWindows)shell.Windows(); SHDocVw.InternetExplorer ie; foreach (object window in windows) { ie = window as SHDocVw.InternetExplorer; if (ie != null && string.Equals(System.IO.Path.GetFileName(ie.FullName), "iexplore.exe", StringComparison.CurrentCultureIgnoreCase)) { if (ie.LocationURL == url) { return ie; } } } return null; }
doc.body doc.getElementsByName doc.getElementsByTagName
mshtml.HTMLDocument doc2 = ie.Document; var frame = doc2.frames.item(int.Parse(configs[2])); var doc = frame.Document; doc.getElementById完了,操作方法基本上都大同小异吧。
public static void runSubWindow(String command) { ProcessStartInfo psInfo = new ProcessStartInfo(); psInfo.FileName = command; psInfo.CreateNoWindow = true; psInfo.UseShellExecute = false; psInfo.RedirectStandardOutput = true; Process p = Process.Start(psInfo); string output = p.StandardOutput.ReadToEnd(); }
传入你的程序的路径,就可以打开它了。
有了上面的知识,你可以自由的发挥了,比如你做一个定时程序,在上班时间自动打卡,然后自己接着睡一会儿....嘘!!这绝对不是我说的。
今天就介绍这么多了,欢迎继续关注我的博客
转载请注明:转自lufy_legend的博客http://blog.csdn.net/lufy_legend用程序来控制一个网页,实现自动输入等操作,布布扣,bubuko.com
原文:http://blog.csdn.net/lufy_legend/article/details/25191765