以下代码适用于您的第一个网站。将输入放在单元格“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