Vb.net 单击webbrowser控件中的链接时,如何避免未经授权的访问异常?

Vb.net 单击webbrowser控件中的链接时,如何避免未经授权的访问异常?,vb.net,winforms,exception,unauthorizedaccessexcepti,Vb.net,Winforms,Exception,Unauthorizedaccessexcepti,我已经创建了一个小的网络机器人来点击网页上的链接,但是我遇到了一个小问题。目前,在一些选定的站点上,当我尝试单击链接时,会出现访问异常。我曾试图对这些问题进行一些研究,但没有发现任何与我的问题相关的东西——大多数都是iFrame的问题,这不适用于我,因为我使用的网站没有任何问题。是什么阻止我点击某些网站而不是其他网站的链接?我能做些什么来解决这个问题 For j = 0 To WebBrowser1.Document.DomDocument.all.length - 1 HTMLElem

我已经创建了一个小的网络机器人来点击网页上的链接,但是我遇到了一个小问题。目前,在一些选定的站点上,当我尝试单击链接时,会出现访问异常。我曾试图对这些问题进行一些研究,但没有发现任何与我的问题相关的东西——大多数都是iFrame的问题,这不适用于我,因为我使用的网站没有任何问题。是什么阻止我点击某些网站而不是其他网站的链接?我能做些什么来解决这个问题

For j = 0 To WebBrowser1.Document.DomDocument.all.length - 1
    HTMLElementMain = WebBrowser1.Document.DomDocument.all.item(j)
    If Not HTMLElementMain Is Nothing Then
        If StrComp(HTMLElementMain.TagName, "a", CompareMethod.Text) = 0 Then
            If HTMLElementMain.href <> Nothing Then
                HTMLElementHrefStr = HTMLElementMain.href
                HTMLElementMain.Click()
            End if
        End if
    End if
Next

到底是什么引发了“访问异常”?这是一个例外,或者你指的是Http 401状态码?为了方便你,我上传了错误跟踪。也许我的眼睛看不清哪里出了问题:)DOM是个例外。HTMLElementHrefStr是脚本函数吗?链接的目标是新帧还是_black?HTMLElementHrefStr只是字符串类型的变量。在那里的代码块中没有调用其他函数。我将研究DOM
System.UnauthorizedAccessException was unhandled
  Message="Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))"
  Source="mscorlib"
  StackTrace:
       at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters)
       at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
       at Microsoft.VisualBasic.CompilerServices.VBBinder.InvokeMember(String name, BindingFlags invokeAttr, Type objType, IReflect objIReflect, Object target, Object[] args, String[] namedParameters)
       at Microsoft.VisualBasic.CompilerServices.LateBinding.InternalLateCall(Object o, Type objType, String name, Object[] args, String[] paramnames, Boolean[] CopyBack, Boolean IgnoreReturn)
       at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateCall(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack, Boolean IgnoreReturn)
       at YTAA.YTAA.btnBegin_Click(Object sender, EventArgs e) in xxxxxxxxxxxxxx
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(ApplicationContext context)
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
       at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
       at YTAA.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: