现在我正在尝试编写一个能够从特定网站下载文件的工具,以及其他一些东西。
我目前的解决方案是,我打开从Internet Explorer下载文件的网站,等待几秒钟以便加载网站,然后发送一个按键到Internet Explorer,即ALT + S,以便保存该文件到标准下载位置。
但是,我的代码在应该发送击键的行中失败。 当然,你会发现它低于它抛出的错误。
我相信你会发现一些有用的事实:
我特别想知道的是:
最重要的是:请注意,我是一名业余爱好程序员,几周前刚刚开始使用VB。如果我错过了一些重要的信息,或者我的代码看起来很奇怪,那么,那就是为什么:)
Sub Download()
Dim IE As Object
IE = CreateObject("InternetExplorer.Application")
Console.WriteLine("Start Download")
IE.Navigate("https://toolslib.net/downloads/finish/1-adwcleaner/") 'Opens the website in Internet Explorer
Do 'Waits for Internet Explorer to be launched before going on
If CBool(Process.GetProcesses.Where(Function(P As Process) _
P.ProcessName = "iexplore").Count) Then
Exit Do
End If
Threading.Thread.Sleep(100)
Loop
IE.Visible = True
Threading.Thread.Sleep(5000) 'Some time for the website to load
IE.SendKeys("%{S}", True)
End Sub
运行此代码时会抛出以下错误。
Note: Line 67 is the line where IE.SendKeys("%{S}", True) stands.
Unhandled Exception: System.ArgumentException: The process {0} wasn't found.
at Microsoft.VisualBasic.CompilerServices.Symbols.Container.InvokeMethod(Method TargetProcedure, Object[] Arguments, Boolean[] CopyBack, BindingFlags Flags)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.CallMethod(Container BaseReference, String MethodName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, BindingFlags InvocationFlags, Boolean ReportErrors, ResolutionFailure& Failure)
at Microsoft.VisualBasic.CompilerServices.NewLateBinding.ObjectLateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn)
bei Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn)
at MyApp.Module1.Download() in C:\Users\User\Documents\Visual Studio 2017\Projects\MyApp\MyApp\Module1.vb:Line 67.
答案 0 :(得分:0)
我在表单应用程序中使用了WebBrowser控件,它工作得很好!
SendKeys.Send("+{TAB}")
System.Threading.Thread.Sleep(1000)
SendKeys.Send("{ENTER}")