• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

IE Java Script and Excel scraping

flyte

New Member
Hi Guys,
I have googled and I find no real joy in regard to this. Is it possible to submit a form and then scrape the results if the format is Java Script? Using VBA?

I need to get data from a web page:
http://education.qld.gov.au/wcis/Enrolment/ListStateSecEnrolments.aspx?CtrCd=0330

I have the following code:
Code:
Sub clickformbutton()
Dim ie As Object
Dim Form As Variant, Button As Variant
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
.navigate ("http://education.qld.gov.au/wcis/Enrolment/ListStateSecEnrolments.aspx?CtrCd=0330")
While ie.ReadyState <> 4
DoEvents
Wend
Set Form = ie.document.getelementsbyTagname("form")
Set Button = Form(0).submit
Form(0).submit
 
End With
End Sub

My code isn't submitting the form to get the results page I want and I cant scrape the result page anyway due to the Java Script.

I am trying to do this from work and am not able to download add-ins, so if there is an answer to my question it would need to be VBA only.

Thanks for your thoughts on this matter.

Natasha
 
Hi,

It may be due slow loading of the pag

Try the below code

Code:
Sub LoginTo()
 
'*Tool->References->Enable Microsoft HTML Object Library & Microsoft Iner net Controls*
  Dim IE As Object
  Application.ScreenUpdating = False
 
  Set IE = CreateObject("InternetExplorer.Application")
 
  IE.Visible = True
  IE.navigate "http://education.qld.gov.au/wcis/Enrolment/ListStateSecEnrolments.aspx?CtrCd=0330"
 
  ' Wait while IE loading...
  While IE.Busy
  DoEvents
  Wend
 
  delay 3
  IE.Document.getElementById("btnSearch").Click
 
  Application.ScreenUpdating = True
End Sub
'-----------------------------------------------------------------------
Private Sub delay(seconds As Long)
  Dim endTime As Date
  endTime = DateAdd("s", seconds, Now())
  Do While Now() < endTime
  DoEvents
  Loop
 
End Sub
 
Thanks heaps Sathish. This code is getting me to the result page I need. You are AWESOME.
 

Hi,

working code on my side :​
Code:
Sub Demo()
    With CreateObject("InternetExplorer.Application")
        .Navigate ("http://education.qld.gov.au/wcis/Enrolment/ListStateSecEnrolments.aspx?CtrCd=0330")
        .Visible = True
        While .ReadyState < 4 Or .Busy:  DoEvents:  Wend

        With .Document.forms("frmListStateSecEnrol")
            While .ReadyState <> "complete":  DoEvents:  Wend
            .Item("btnSearch").Click
        End With
    End With
    End
End Sub


Works too without line While .ReadyState <> "complete"
If same on your side, code can be reduced :​
Code:
Sub Demo()
    With CreateObject("InternetExplorer.Application")
        .Navigate ("http://education.qld.gov.au/wcis/Enrolment/ListStateSecEnrolments.aspx?CtrCd=0330")
        .Visible = True
        While .ReadyState < 4 Or .Busy:  DoEvents:  Wend
        .Document.forms("frmListStateSecEnrol")("btnSearch").Click
    End With
    End
End Sub

When I need a delay I use VBA Wait function or a pause procedure.​
 
Last edited:
Thanks heaps Mark L. That is a really nice neat bit of code and it works so fast. Very Much appreciated.
Natasha
 

LoL ‼

And my code doesn't need any reference - late binding - : best in case of sharing workbook on other computers.

Using references - early binding - is great during development : autofilling, object inspection, …​
 
Last edited:
Back
Top