Wait for window to reload when scrolling web page in VBA

前端 未结 2 1435
后悔当初
后悔当初 2021-01-26 11:54

I have written a VBA macro to count the (approximate) number of images returned for a Google search of a specific term. By approximate I mean that the program should count the n

2条回答
  •  伪装坚强ぢ
    2021-01-26 12:21

    Just do this instead, I am sure you can find a nicer way to do it (if you think it's worth the time) but this should be fine :

    newNum = -1
    Set objIE = New InternetExplorer
    objIE.navigate fullUrl
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
    Set currPage = objIE.document
    Do Until oldNum = newNum
        oldNum = newNum
        newNum = currPage.getElementById("rg_s").getElementsByClassName("rg_di rg_bx rg_el ivg-i").Length        
        Application.Wait Now + TimeSerial(0, 0, 2)
        currPage.parentWindow.scrollBy 0, 100000        
        Application.Wait Now + TimeSerial(0, 0, 2)
        If newNum > 400 Then newNum = 400
    Loop
    

    Then you just have to adapt the delay in TimeSerial depending on how fast your computer loads ( in here I set in to 2 seconds)

提交回复
热议问题