访问VBA getelementsbytagname windows 10 issue?

时间:2015-12-19 19:35:09

标签: vba internet-explorer-11 ms-access-2013

我有Access VBA脚本从许多网站提取数据。这些与Office 2013和Windows 7完美配合。但是,由于升级到Windows 10,我遇到了间歇性错误(不一定在同一个地方使用相同的数据),或者有时数据没有从标签中提取。当我访问具有特定索引的特定标记时,似乎也会出现这种情况,例如

tempV = TDelement.getElementsByTagName("td")(0).innerText

我正在使用IE作为浏览器对象创建如下:

Set objIE = CreateObject("InternetExplorer.Application")

升级Windows有什么破坏的吗? (新手,对任何不正确的术语表示歉意)

1 个答案:

答案 0 :(得分:2)

考虑将MSXML的IXMLHTTPRequest对象用于Web服务器请求。 IE不再是Windows上的专用浏览器,因此可能无法完全支持Windows 10的自动化。

Dim Req As Object, xmlobj As Object
Dim strWeb As String, myFile As String

' READ HTML PAGE
Set Req = CreateObject("MSXML2.XMLHTTP")
Req.Open "GET", "http://www.example.coms/", False
Req.send

' HTML/TEXT
strWeb = Req.responseText
myFile = "C:\Path\To\File.txt"
Open myFile For Output As #1
Write #1, strWeb
Close #1

' XML
Set xmlObj = CreateObject("MSXML2.DOMDocument")
myFile = "C:\Path\To\File.xml"
xmlObj.LoadXML Req.responseText
xmlObj.Save myFile

Set Req = Nothing
Set xmlObj = Nothing
相关问题