-->

自动化错误:800706B5,80004005,80010108出现内部SAP网站刮(Automat

2019-09-21 03:19发布

我写一个宏,将刮的供应商信息,我公司的内部SAP网站。 由于一些原因我不得不使用VBA这样做。 不过,我想不通为什么我不断收到这三个错误,当我试图刮页面。 难道这有什么做的UAC完整性模型 ? 或者是有什么错我的代码? 是否有可能使用HTTP网页可以在Internet Explorer中不同的处理方式? 我可以去任何网页,甚至其他内部网页,并可以刮每个那些就好了。 但是,当我试图刮SAP页面,我得到这些错误。 错误描述和发生的时候,他们是:

800706B5 - 该接口是未知的(当我运行问题的代码之前放置断点发生时)

80004005 - 未指定的错误(当我不把任何错误,只是让宏运行时)

80010108 - 调用已经与其客户端断开连接的对象。 (我似乎无法得到这个错误的发生相一致,似乎身边的时候发生的东西在Excel中是如此破坏,没有页面会加载,我必须重新安装Excel)

我完全不知道是怎么回事。 该完整性页面并没有太大的意义给我,而我对这个发现,研究讲到连接到数据库,并使用ADO和COM引用。 但是我通过Internet Explorer做的一切。 这是我下面相关的代码:

Private Sub runTest_Click()
   ie.visible = True
   doScrape
End Sub
'The code to run the module
Private Sub doTest()
   Dim result As String
   result = PageScraper.scrapeSAPPage("<some num>")
End Sub

PageScraper模块

Public Function scrapeSAPPage(num As Long) As String
   'Predefined URL that appends num onto end to navigate to specific record in SAP
   Dim url As String: url = "<url here>" 
   Dim ie as InternetExplorer
   set ie = CreateObject("internetexplorer.application")
   Dim doc as HTMLDocument

   ie.navigate url 'Will always sucessfully open page, regardless of SAP or other
   'pauses the exection of the code until the webpage has loaded
   Do
     'Will always fail on next line when attempting SAP site with error
     If Not ie.Busy And ie.ReadyState = 4 Then 
        Application.Wait (Now + TimeValue("00:00:01"))
        If Not ie.Busy And ie.ReadyState = 4 Then
           Exit Do
        End If
     End If
     DoEvents
   Loop

   Set doc = ie.document 'After implementation of Tim Williams changes, breaks here
   'Scraping code here, not relevant

 End Function

我在Windows 7机器上使用IE9和Excel 2010。 任何帮助或洞察力,您可以提供将不胜感激。 谢谢。

Answer 1:

我做这类经常刮,并发现它做非常困难IE自动可靠地工作100%,像那些你已经发现的错误。 因为它们通常时序问题它可以是非常令人沮丧的调试,因为他们当你逐步完成,只有在现场运行,以最大限度地减少我做了以下的错误不出现:

引入更多的延迟; ie.busy和ie.ReadyState未必能得到有效回答的ie.navigate后,立即使引进ie.navigate经过短暂的延迟。 对于事情我加载1到2秒正常,但任何超过500ms的似乎工作。

确保IE是在干净的状态下会ie.navigate“关于:空白”才去的目标URL。

在此之后,你应该有一个有效的IE对象,你必须看它,看看你有什么里面。 一般来说,我避免尝试访问整个ie.document,而使用IE.document.all.tags(“X”),其中“x”是我正在寻找诸如TD或一个合适的事情。

但是毕竟这些改进虽然他们已经增加了我的成功率还是有随机误差。

我真正的解决办法是放弃IE,转而使用XMLHTTP做我的工作。

如果您正在使用文档的文本操作解析出数据那么这将是一个没有脑子掉了。 XMLHTTP对象是更可靠。 而你刚刚获得了“responseText的”访问文档的完整的HTML。

下面是我用在什么产品,现在刮的简化版本,它是如此可靠运行一夜之间产生数百万行没有错误。

Public Sub Main()

Dim obj As MSXML2.ServerXMLHTTP
Dim strData As String
Dim errCount As Integer

' create an xmlhttp object - you will need to reference to the MS XML HTTP library, any version will do
' but I'm using Microsoft XML, v6.0 (c:\windows\system32\msxml6.dll)
Set obj = New MSXML2.ServerXMLHTTP

' Get the url - I set the last param to Async=true so that it returns right away then lets me wait in
' code rather than trust it, but on an internal network "false" might be better for you.
obj.Open "GET", "http://www.google.com", True
obj.send ' this line actually does the HTTP GET

' Wait for a completion up to 10 seconds
errCount = 0
While obj.readyState < 4 And errCount < 10
    DoEvents
    obj.waitForResponse 1 ' this is an up-to-one-second delay
    errCount = errCount + 1
Wend

If obj.readyState = 4 Then ' I do these on two
    If obj.Status = 200 Then ' different lines to avoid certain error cases
        strData = obj.responseText
    End If
End If

obj.abort  ' in real code I use some on error resume next, so at this point it is possible I have a failed
           ' get and so best to abort it before I try again

Debug.Print strData

End Sub

希望帮助。



文章来源: Automation Errors: 800706B5, 80004005, 80010108 appear for internal SAP site scrape