您的位置:首页 > 编程语言 > VB

VBS统计页面加载时间脚本

2010-03-04 13:24 375 查看
下面是一个通过Excel中的url列表来请求页面,统计页面加载时间,然后记录到Excel中的vbs脚本。由于vbs脚本并不是这方面的最好选择,没有研究过httpWatch软件是如何实现统计页面各个元素加载时间的原理,这个脚本统计出来的时间会有偏差,数据仅供参考。以下是代码:

'Function GetCellNum()
'    On Error Resume Next
'    Set Wshell = CreateObject("Wscript.shell")
'    Set ExcelApp = CreateObject("Excel.Application")
'    ExcelApp.Visible = True
'    Set newBook = ExcelApp.Workbooks.Open("C:/Report.xls")
'    If Err = 0 Then
'            Set excelSheet = ExcelApp.ActiveSheet
'            Set rowCount = excelSheet.Rows.Count
'            For i = 1 To 65535
'                GetCellValue = excelSheet.Cells(i,1)
'                excelSheet.Cells(i,2) = "http://test.gasgoo.cn/TradeSearch/search/SearchNormal.aspx?idty=0.2831222238019109&sType=1&key=" & GetCellValue & ""
'                excelSheet.save
'MsgBox "现在是第"&i&"行"&vbCrLf&"值为:"&GetCellValue
'                Wshshell.Popup GetCellValue,2,"获取的Excel单元格的值为:",0+64
'                If GetCellValue = "" Then
'                    rowNum = i - 1
'                    GetCellNum = rowNum
'                    MsgBox rowNum
'                    Exit For
'                Else
'do nothing
'                End If
'            Next
'        Else
'do nothing
'    End If

'    newBook.SaveAs("C:\KeywordUrl.xls")
'    newBook.Save
'    newBook.Close
'    ExcelApp.Quit

'    Set ExcelApp = Nothing
'    Set Wshell = Nothing
'End Function

'Call GetCellNum()
'i = GetCellNum()
'MsgBox i

Function CountPadLoadTime()
On Error Resume Next
Set Wshell = CreateObject("Wscript.shell")
Set IeObject = CreateObject("InternetExplorer.Application")
Set ExcelApp = CreateObject("Excel.Application")
ExcelApp.Visible= True

Set newBook =ExcelApp.Workbooks.Open("C:/KeywordUrl.xls")

If Err = 0 Then
Set excelSheet = ExcelApp.ActiveSheet

For i = 1 To 65535
GetCellValue = excelSheet.Cells(i,2)
If GetCellValue <> "" Then
'MsgBox GetCellValue
IeObject.Navigate(GetCellValue)
time1 = timer()
'MsgBox time1
a = IeObject.ReadyState
IeObject.visible = True
While IeObject.busy Or ( IeObject.ReadyState<>4 )
wscript.sleep 1
wend
time2 = timer()
'MsgBox time2

costPageLoad = time2 - time1

'Wshshell.Popup costPageLoad,2,"页面加载时间为:",0+64

'MsgBox "页面加载时间为:"& costPageLoad

excelSheet.Cells(i,3) = costPageload
excelSheet.save

WScript.Sleep 1000

time1 = 0
time2 = 0
costPageLoad = 0

Else
Exit For
End If
Next
End If
newBook.SaveAs("c:\Results.xls")
newBook.Close
excelApp.Quit

Call RelaeseResource()
End Function

Function ReleaseResource()
On Error Resume Next
Set excelObject = Nothing
Set ExcelApp = Nothing
Set IeObject = Nothing
End Function

Call CountPadLoadTime()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: