【问题标题】:How to automate check for multiple website time taken to load from excel?如何自动检查从excel加载所需的多个网站时间?
【发布时间】:2016-05-05 16:29:59
【问题描述】:

我在 Excel 中有大约 100 个网站,我需要检查网站加载所需的时间。 目前,我正在 Internet Explorer 中通过使用开发人员工具(F12)> Network> Taken(Column)一一手动执行此操作。 有没有办法自动进行这项检查?

【问题讨论】:

  • 默认没有内置解决方案。但是您可以在 VBA 中编写一些代码或寻找插件来完成这项工作。

标签: excel excel-formula vba


【解决方案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 了解有关引用所需应用程序的信息。

【讨论】:

  • 刚刚意识到我在错误的地方启动了计时器,代码已被修改,
猜你喜欢
  • 2022-07-13
  • 2017-06-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-18
  • 2022-01-15
相关资源
最近更新 更多