简体   繁体   English

Excel中的Web查询出现问题

[英]Trouble with Web Query in Excel

I´m having some trouble with two different web queries in Excel. 我在使用Excel中的两个不同的Web查询时遇到了麻烦。

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

Trouble: I can´t seem to obtain the result value of the query. 问题:我似乎无法获得查询的结果值。 Basically, I´m inputting the parameters in an excel spreadsheet and I want the result. 基本上,我在excel电子表格中输入参数,然后得到结果。 I don´t know if is related, but the result only exists after you press calculate. 我不知道是否相关,但是结果仅在您按下计算后才存在。 Seems easy, but I having some trouble... 看起来很简单,但是我遇到了一些麻烦...

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

Trouble: I believe that maybe this one is not related to the query itself, since I do get data, but the results seems to be encrypted.. I simply can´t tell if it is something I'm doing wrong or if there is some way to overcome this. 麻烦:我相信这可能与查询本身无关,因为我确实获得了数据,但是结果似乎是加密的。我根本无法分辨这是我做错了还是有错一些克服这个问题的方法。

From my perspective, even though the first one SEEMS to be easier to fix, the second one would be extremely helpful for my research. 从我的角度来看,尽管第一个SEEMS更容易修复,但第二个对我的研究将非常有帮助。

I appreciate any help you can give me. 感谢您能给我的任何帮助。

Thanks, 谢谢,

For the iea, they want you to subscribe to their 'online data services' so they encode all of the search result data. 对于iea,他们希望您订阅其“在线数据服务”,以便对所有搜索结果数据进行编码。

For danielsoper, the results are generated via ASP, so you won't be able to get them form a web query. 对于danielsoper,结果是通过ASP生成的,因此您将无法通过Web查询获得它们。 You can get them by using VBA and MSXML, but you'd be better off just replicating the algorithm in VBA or fining a different website. 您可以使用VBA和MSXML来获得它们,但是最好仅在VBA中复制算法或优化其他网站。

The following code works for me at your first website. 以下代码可在您的第一个网站上为我工作。 Place the inputs in cells "A1" and "A2" and the results are placed in "A3" and "A4". 将输入放置在单元格“ A1”和“ A2”中,结果放置在“ A3”和“ A4”中。 Modify to fit your worksheet. 进行修改以适合您的工作表。

' 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