Links seem to be inside H3 tags. Typically, to verify page load, you may need the following:
Private Declare Sub Sleep Lib "kernel32" (ByVal nMilliseconds As Long) Sub UseIE() Dim ie As Object Dim thePage As Object Dim strTextOfPage As String Set ie = CreateObject("InternetExplorer.Application") 'ie.FullScreen = True With ie '.Visible = True .Navigate "http://www.bbc.co.uk" While Not .ReadyState = READYSTATE_COMPLETE '4 Sleep 500 'wait 1/2 sec before trying again Wend End With Set thePage = ie.Document 'more code here End Sub
However, I would instead try to reference element A in the first H3 using getElementsByTagName("H3") , get the first of these elements, and then look inside that for the A-link and its href attribute.
In JavaScript, attempts to reference non-existent elements return undefined , but from VBA it will probably need error handling code.
As soon as I got href , I would stop navigation (not sure about the command for this, perhaps ie.Stop ) or go straight to the next page.
However, the first link (s) will often be supported by the links, and the returned href is slightly distorted. The text of these sponsored links includes em tags. I can use this information to drop these links and look further down the page.
I do not know if there is a better way to do this.
Andy g
source share