IE.Document waiting before interacting with a page (1 Viewer)

wackywoo105

Registered User.
Local time
Today, 02:16
Joined
Mar 14, 2014
Messages
203
I've been using:

Code:
While IE.busy
   DoEvents
Wend
Loop

between pages.

although on initial load I use:

Code:
Do Until IE.ReadyState = 4 And Not IE.busy
    DoEvents
Loop

I note if I interact with a page just after loading I get an error so have added:

Code:
x = Timer + 2
Do While Timer < x
    DoEvents
Loop

Can anyone help with the best code to use between pages before I try something like ticking a box?
 

Edgar_

Active member
Local time
Today, 04:16
Joined
Jul 8, 2023
Messages
430
For waiting in seconds:
Code:
#If VBA7 Then
     Private Declare PtrSafe Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
#Else
     Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
#End If

Example: wait 1 second
Sleep 1000

For awaiting document completion:
Code:
Do While Not ie.ReadyState = READYSTATE_COMPLETE 'can also be 4
    Debug.Print "Loading stage " & ie.ReadyState + 1 & "/5"
    DoEvents
Loop

There are other more drastic methods, like:
Code:
Do While doc Is Nothing
    On Error Resume Next
    Set doc = ie.Document
    On Error GoTo 0
Loop

You can use a combination of all of these as well.

Check if the attached is of any help, it scrapes this forum. Don't abuse it.
 

Attachments

  • ScrapeAWF.accdb
    424 KB · Views: 34

Gasman

Enthusiastic Amateur
Local time
Today, 10:16
Joined
Sep 21, 2011
Messages
14,301
Very nice @Edgar_
However I was expecting to see a list that mirrored the page, but it does not?
So what is it actually retrieving?

1700637836991.png

1700637862961.png
 

Edgar_

Active member
Local time
Today, 04:16
Joined
Jul 8, 2023
Messages
430
So what is it actually retrieving?
Since the concept here is to wait for page loads, in the given example, it loads the first page, waits for its completion, and then extracts the thread at the top of the list. This sequence is repeated for subsequent pages up to page 11, ensuring each page is fully loaded before proceeding to extract the desired thread, which is always the one at the top of each page.

Extracting all threads is also possible, but I wanted the continuous form to be filled rather slowly, so I chose to only extract one thread per page. What constitutes the top thread? for simplicity, the one with index 0 when retrieving from document.getElementsByClassName(theClassName)(0)

You could add another loop there to go from 0 to N, but I didn't test it, so I don't really know if that's consistent.
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:16
Joined
Sep 21, 2011
Messages
14,301
Ok, thank you.

Neat. (y)
 
Last edited:

Users who are viewing this thread

Top Bottom