繁体   English   中英

Excel中的Web查询出现问题

[英]Trouble with Web Query in Excel

我在使用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

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

从我的角度来看,尽管第一个SEEMS更容易修复,但第二个对我的研究将非常有帮助。

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

谢谢,

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

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

以下代码可在您的第一个网站上为我工作。 将输入放置在单元格“ 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM