VBA webscraping for onclick

seph187

New Member
Joined
Jun 2, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have been trying to use VBA to webscrape some data,

however, i have not much success being able to click on the hyperlink or call the onclick function. Help will be very much appreciated. My code is listed below as well

the only HTML information is listed as below

<tr class="linkable" onclick="window_directory_member('display.php?UidNum=410640'); return false;">

Code:
Sub webscrape()     
    Dim objIE As InternetExplorer 'special object variable representing the IE browser
    Dim aEle As HTMLLinkElement 'special object variable for an <a> (link) element
    Dim y As Integer 'integer variable we'll use as a counter
    Dim result As String 'string variable that will hold our result link
    Dim HTMLElement As Object
    Dim html As Object
 
    Set objIE = New InternetExplorer
    objIE.Visible = True

    objIE.FullScreen = False
    
    objIE.navigate "https://www.theclearinghouse.org/uid-lookup"
    
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
    
    objIE.Visible = True
    
    objIE.document.getElementsByTagName("iframe")(0).contentDocument.getElementById("UidNum2").Value = "410640"

    objIE.document.getElementsByTagName("iframe")(0).contentDocument.getElementById("SubmitUid").Click
    
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Well, I thought your code worked perfectly! The clicking method worked and toook me through to the details page. Mind you, I was stepping through the code (pressing F8), so I was moving slower than IE would if left to its own devices. Given this, it would seem to suggest that you need to slow IE down a bit before clicking. Do you have a subroutine that can do that? If not, I'll dig one out.
 
Upvote 0
Actually, you know what - I just ran it at normal speed and it still worked fine, so I don't know what to tell you - on the plus side, your code is perfect! :-)

If you need it, here's the code I use for pause the computer - there are other (and probably better) routines, but this one has never let me down. To run it, you add how many seconds you want tit to pause for as an argument, so: PAUSE 3 will pause for 3 seconds, and so on...

VBA Code:
Sub PAUSE(Period As Single)
    Dim T As Single
    T = Timer
    Do
        DoEvents
    Loop Until T + Period < Timer     
End Sub
 
Upvote 0
Actually, you know what - I just ran it at normal speed and it still worked fine, so I don't know what to tell you - on the plus side, your code is perfect! :)

If you need it, here's the code I use for pause the computer - there are other (and probably better) routines, but this one has never let me down. To run it, you add how many seconds you want tit to pause for as an argument, so: PAUSE 3 will pause for 3 seconds, and so on...

VBA Code:
Sub PAUSE(Period As Single)
    Dim T As Single
    T = Timer
    Do
        DoEvents
    Loop Until T + Period < Timer    
End Sub
Hi Dan, i have not coded the last portion which is to click the UID one more time in order for the popup to show. Thank you so much for trying though.
 
Upvote 0
Ahh - I had assumed that the link you weren't able to click on was the last one in your code. I didn't realise that you were intending to progress further. I'll have a look if I get a chance this weekened, but the only thing that comes immediately to mind is that you can always execute javascript by: objIE.document.parentWindow.execScript(INSERTSCRIPTHERE, "javascript"). Do let me know if you manage to solve it before I get a chance to take a crack at it.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top