(Solved) – Cannot click links on HTML or possible XML webpage

(solved)-–-cannot-click-links-on-html-or-possible-xml-webpage

I have written the below code to query a webpage and scrape results. Next steps are to click each name and pull additional data from the subsequent webpages. I return a Permission Denied error when clicking any additional links after the first name.

Sub polygraphers()

Dim ie As Object
Dim twb As Workbook
Dim cont As Variant

Set twb = ThisWorkbook

Set ie = CreateObject("internetexplorer.application")

For Each st In Range("A1:A50") ' & Range("A" & Rows.Count).End(xlUp).Row)

With ie
    .navigate "https://www.polygraph.org/find-a-member#/"
    .Visible = True
Do While .Busy Or .readyState <> 4
DoEvents
Loop
End With

Application.Wait Now   #12:00:05 AM#

Set dd = ie.document.getElementsByTagName("option")
Set ddd = ie.document.getElementsByTagName("select")
'On Error Resume Next
For Each d In dd
If d.getAttribute("label") = st Then
d.Selected = True
Set evt = ie.document.createEvent("keyboardevent")
evt.initEvent "change", True, False
d.dispatchEvent evt
End If
Next d

Set atags = ie.document.getElementsByTagName("a")
For Each atag In atags
If atag.className = "gen-button" Then
atag.Click
End If
Next atag
Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop
Application.Wait Now   #12:00:05 AM#

Set stags = ie.document.getElementsByTagName("strong")
For Each stag In stags
If stag.className = "ng-binding" Then
stateres = Left(stag.innertext, InStr(stag.innertext, " "))
Exit For
End If
Next stag

Set spantags = ie.document.getElementsByTagName("span")
For Each span In spantags
If InStr(span.innertext, "Zip") > 0 Then
Range("L" & Range("L" & Rows.Count).End(xlUp).Row   1).Value = Right(span.innertext, Len(span.innertext) - InStr(span.innertext, "e"))
Range("K" & Range("K" & Rows.Count).End(xlUp).Row   1).Value = st
ElseIf InStr(span.innertext, "Field") > 0 Then
Range("J" & Range("J" & Rows.Count).End(xlUp).Row   1).Value = Right(span.innertext, 2)
Else
End If
Next span

Set ohtmldoc = ie.document
Set oxml = New MSXML2.DOMDocument60

sxml = ohtmldoc.DocumentElement.outerHTML
oxml.LoadXML (sxml)

Not sure where to go from here. I want to click into each name and execute additional code on the subsequent pages. Thanks in advance.

Leave a Reply

Your email address will not be published. Required fields are marked *