我在excel中有大约100个网站,我需要检查网站加载的时间。 目前,我使用开发人员工具(F12)>在Internet Explorer中手动执行此操作。网络>采取(专栏)一个接一个。 有没有办法自动检查?
答案 0 :(得分:1)
不确定你的VBA水平,这远非完美,但作为一个起点,这是我通常用来刮网站的代码,但我稍微修改了每个网站打开需要多长时间。这假设您将所有网站都放在A
列中,它将打印在B
列中打开网站所用的时间。请记住,这是宏每个网站运行时间的时间,因此不完全准确到实际网站加载的时间。
Enum READYSTATE
READYSTATE_UNINITIALIZED = 0
READYSTATE_LOADING = 1
READYSTATE_LOADED = 2
READYSTATE_INTERACTIVE = 3
READYSTATE_COMPLETE = 4
End Enum
Sub ImportWebsiteDate()
'to refer to the running copy of Internet Explorer
Dim ie As InternetExplorer, WDApp As Object, staTime As Double, elapsedTime As Double
'to refer to the HTML document returned
Dim html As HTMLDocument, websiteNo As Integer, curSite As String
websiteNo = Range("A500").End(xlUp).Row
'open Internet Explorer in memory, and go to website
Set ie = New InternetExplorer
For i = 1 To websiteNo
curSite = Cells(i, 1).Value
ie.Visible = False
staTime = Timer
ie.navigate curSite
'Wait until IE is done loading page
Do While ie.READYSTATE <> READYSTATE_COMPLETE
Application.StatusBar = "Trying to go to " & curSite
DoEvents
Loop
elapsedTime = Round(Timer - staTime, 2)
Cells(i, 2).Value = elapsedTime
Next i
Set ie = Nothing
Application.StatusBar = False
Application.ScreenUpdating = False
End Sub
如果您复制并粘贴,这不仅有效,请阅读this site以获取有关引用所需应用程序的信息。