【问题标题】:Trouble with Web Query in ExcelExcel 中的 Web 查询问题
【发布时间】:2013-11-29 20:43:19
【问题描述】:

我在 Excel 中处理两个不同的 Web 查询时遇到了一些问题。

1) 网址:http://www.danielsoper.com/statcalc3/calc.aspx?id=44

问题:我似乎无法获得查询的结果值。基本上,我在 Excel 电子表格中输入参数,我想要结果。我不知道是否相关,但结果仅在您按下计算后才存在。看起来很简单,但我遇到了一些麻烦......

2) 网址:http://www.iea.org/statistics/statisticssearch/report/?&country=USA&year=2011&product=Balances

麻烦:我相信这可能与查询本身无关,因为我确实获得了数据,但结果似乎是加密的。我根本无法判断这是我做错了什么还是如果有办法克服这个问题。

在我看来,尽管第一个看起来更容易修复,但第二个对我的研究非常有帮助。

感谢您能给我的任何帮助。

谢谢,

【问题讨论】:

  • 至于1),你的计算设置为手动吗?尝试将其更改为自动。至于 2),您在这里并没有给我们太多帮助。 “似乎已加密”是什么意思?你得到什么结果,你期望它输出什么?

标签: excel encryption web excel-web-query


【解决方案1】:

对于 iea,他们希望您订阅他们的“在线数据服务”,以便他们对所有搜索结果数据进行编码。

对于 danielsoper,结果是通过 ASP 生成的,因此您无法通过网络查询获得它们。您可以通过使用 VBA 和 MSXML 来获得它们,但您最好在 VBA 中复制算法或完善其他网站。

【讨论】:

  • 1) 所以坚持下去是没有意义的,对吧?是这样,谢谢你的时间! 2) 这实际上很棒......我可以解决它,但我希望让它变得更容易,但是没关系!
  • 是的,我想是的。至少我不知道有什么方法可以得到正确的数据。
【解决方案2】:

以下代码适用于您的第一个网站。将输入放在单元格“A1”和“A2”中,结果放在“A3”和“A4”中。修改以适合您的工作表。

' Open IE, navigate to the website of interest and loop until fully loaded
Set ie = CreateObject("InternetExplorer.Application")

With ie
    .Visible = True
    .navigate "http://www.danielsoper.com/statcalc3/calc.aspx?id=44"
    .Top = 50
    .Left = 530
    .Height = 400
    .Width = 400

Do Until Not ie.Busy And ie.ReadyState = 4
    DoEvents
Loop

End With

' Insert data from cells "A1" and "A2" into the webpage and click "Calculate!"
ie.Document.getElementById("pageContent_gridParameters_txtParameterValue_0").Value = Range("A1")
ie.Document.getElementById("pageContent_gridParameters_txtParameterValue_1").Value = Range("A2")
ie.Document.getElementById("pageContent_btnCalc").Click

' Collect the results and place them on the activesheet
my_var = ie.Document.body.innerhtml

pos_1 = InStr(1, my_var, "Result_0", vbTextCompare)
pos_2 = InStr(pos_1, my_var, ">", vbTextCompare)
pos_3 = InStr(pos_1, my_var, "<", vbTextCompare)
One_Tailed = Mid(my_var, 1 + pos_2, pos_3 - (1 + pos_2))

pos_4 = InStr(pos_3, my_var, "Result_1", vbTextCompare)
pos_5 = InStr(pos_4, my_var, ">", vbTextCompare)
pos_6 = InStr(pos_5, my_var, "<", vbTextCompare)
Two_Tailed = Mid(my_var, 1 + pos_5, pos_6 - (1 + pos_5))

Range("A3") = One_Tailed
Range("A4") = Two_Tailed

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多