Cheerio 不能等待节点获取

问题描述

Option Explicit

Sub FindAndHighlight()

    ' You Could use these constants ('ByVal') as arguments of this procedure,' when you Could call it with 'FindAndHighlight "2",34' from yet another
    ' procedure.
    Const SearchString As String = "2"
    Const cIndex As Long = 34
    
    If ActiveSheet Is nothing Then Exit Sub ' if run from add-in
    If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub ' if e.g. chart
    'Debug.Print "Worksheet Name:       " & ActiveSheet.Name
    
    Dim srg As Range: Set srg = ActiveSheet.UsedRange
    'Debug.Print "Source Range Address: " & srg.Address(0,0)
    
    Dim frg As Range: Set frg = refFindStringInRange(srg,SearchString)
    If frg Is nothing Then
        MsgBox "No occurrence of '" & SearchString & "' found in range '" _
            & srg.Address(0,0) & "' of worksheet '" & srg.Worksheet.Name _
            & "'.",vbCritical,"nothing Found"
        Exit Sub
    End If
    'Debug.Print "Found Range Address:  " & frg.Address(0,0)
    
    HighLightRangeUsingColorIndex frg,cIndex

End Sub

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose:      Creates a reference to a range combined of all cells
'               whose contents are equal to a string.
' Remarks:      The search is case-insensitive ('MatchCase') and is performed
'               by rows ('SearchOrder') ascending ('SearchDirection','               ('FindNext')),starting with the first cell ('After')
'               of each area of the range.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function refFindStringInRange( _
    ByVal SearchRange As Range,_
    ByVal SearchString As String) _
As Range

    If SearchRange Is nothing Then Exit Function
    
    Dim frg As Range
    Dim arg As Range
    Dim lCell As Range
    Dim fCell As Range
    Dim FirstAddress As String
    
    For Each arg In SearchRange.Areas
        Set lCell = arg.Cells(arg.Rows.Count,arg.Columns.Count)
        Set fCell = nothing
        ' By modifying the parameters of the arguments of the 'Find' method
        ' you can change the behavior of the function in many ways.
        Set fCell = arg.Find(SearchString,lCell,xlFormulas,xlWhole,xlByRows)
        If Not fCell Is nothing Then
            FirstAddress = fCell.Address
            Do
                If frg Is nothing Then
                    Set frg = fCell
                Else
                    Set frg = Union(frg,fCell)
                End If
                Set fCell = arg.FindNext(After:=fCell)
            Loop Until fCell.Address = FirstAddress
        End If
    Next arg
      
    If Not frg Is nothing Then
        Set refFindStringInRange = frg
    End If
    
End Function

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Purpose:      Highlights the cells of a range using a color index.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub HighLightRangeUsingColorIndex( _
        ByVal rg As Range,_
        ByVal cIndex As Long)
    If rg Is nothing Then Exit Sub
    If cIndex < 1 Or cIndex > 56 Then Exit Sub
    rg.Interior.ColorIndex = cIndex
End Sub

while 循环在从 fetch 中获取所有 html 代码之前结束

我不知道如何等待 html 代码从 fetch 中加载到cheerio

我尝试使用 setTimeout 但不起作用

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)