[英]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.