自动化错误:800706B5,80004005,80010108出现内部SAP网站刮 [英] Automation Errors: 800706B5, 80004005, 80010108 appear for internal SAP site scrape

查看:1041
本文介绍了自动化错误:800706B5,80004005,80010108出现内部SAP网站刮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am writing a macro that will scrape my company's internal SAP site for vendor information. For several reasons I have to use VBA to do so. However, I cannot figure out why I keep getting these three errors when I attempt to scrape the page. Is it possible that this has something to do with the UAC integrity model? Or is there something wrong with my code? Is it possible for a webpage using http can be handled differently in internet explorer? I am able to go to any webpage, even other internal webpages, and can scrape each of those just fine. But when i attempt to scrape the SAP page, i get these errors. The error descriptions and when they occur are:

800706B5 - 该接口是未知的(当我运行的违规code之前设置断点时)

800706B5 - The interface is unknown (occurs when I place breakpoints before running the offending code)

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

80004005 - Unspecified error (occurs when I don't place any errors and just let the macro run)

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

80010108 - The Object invoked has disconnected from its clients. (I can't seem to get a consistent occurrence of this error, it seems to happen around the time that something in excel is so corrupted that no page will load and i have to reinstall excel)

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

I have absolutely no idea what is going on. The Integrity page didn't make much sense to me, and all the research I found on this talked about connecting to databases and using ADO and COM references. However I am doing everything through Internet Explorer. Here is my relevant code below:

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模块

PageScraper Module

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。任何帮助或洞察力,您可以提供将大大AP preciated。谢谢你。

I am using IE9 and Excel 2010 on a Windows 7 machine. Any help or insight you can provide would be greatly appreciated. Thank you.

推荐答案

我做这类经常刮,并发现它做非常困难的IE浏览器自动可靠地工作100%的有像你已经发现的错误。因为他们往往​​计时问题,因为它们时,你只在现场跑步,为了最大限度地减少我下面的错误不会出现它可以是非常令人沮丧的调试:

I do this type of scraping frequently and have found it very difficult to make IE automation work 100% reliably with errors like those you have found. As they are often timing issues it can be very frustrating to debug as they don't appear when you step through, only during live runs To minimize the errors I do the following:

引入更多的延迟​​; ie.busy和ie.ReadyState不一定给出有效回答的ie.navigate后,立即,所以引进ie.navigate经过短暂的延迟。对于事情我加载1到2秒正常,但任何超过500ms的似乎工作。

Introduce more delays; ie.busy and ie.ReadyState don't necessarily give valid answers IMMEDIATELY after an ie.navigate, so introduce a short delay after ie.navigate. For things I'm loading 1 to 2 seconds normally but anything over 500ms seems to work.

确认IE是在干净的状态下会ie.navigate关于:空白。临睡前目标网址

Make sure IE is in a clean state by going ie.navigate "about:blank" before going to the target url.

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

After that you should have a valid IE object and you'll have to look at it to see what you've got inside. Generally I avoid trying to access the entire ie.document and instead use IE.document.all.tags("x") where 'x' is a suitable thing I'm looking for such as td or a.

后,但是,所有这些改进虽然他们增加了我的成功率还是有误差是随机的。

However after all these improvements although they have increased my success rate I still have errors at random.

我的真正的解决方案已经抛弃IE,转而使用XMLHTTP做我的工作。

My real solution has been to abandon IE and instead do my work using xmlhttp.

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

If you are parsing out your data using text operations on the document then it will be a no-brainer to swap over. The xmlhttp object is MUCH more reliable. and you just get the "responsetext" to access the entire html of the document.

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

Here is a simplified version of what I'm using in production now for scraping, it's so reliable it runs overnight generating millions of rows without error.

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

希望有所帮助。

这篇关于自动化错误:800706B5,80004005,80010108出现内部SAP网站刮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆