lundi 4 septembre 2017

Data scraping using VBA through Multiple Links on single webpage

I am trying to download data through redirecting the page using click function. The second page gets opened but the problem is the required download is not getting started.

Public Sub CommandButton1_Click() Dim ie As InternetExplorer Dim htmldoc1 As MSHTML.IHTMLDocument 'Document object Dim HTMLInput As MSHTML.IHTMLElement 'Element collection for "input" tags Dim HTMLAs As MSHTML.IHTMLElementCollection Dim HTMLA As MSHTML.IHTMLElementCollection Dim HTMLBs As MSHTML.IHTMLElementCollection 'Element collection for th tags Dim HTMLInputs As MSHTML.IHTMLElement Dim htmldoc2 As MSHTML.IHTMLDocument 'Open InternetExplorer Set ie = CreateObject("InternetExplorer.Application") ie.Visible = True 'make IE invisible

'Navigate to webpage
Dim ieURL As String:    ieURL = "http://ift.tt/2x4OYCG"                        'set URL from which to retrieve racemeet and date data
    ie.navigate ieURL                                                                                 'navigate to URL
    Do While ie.readyState <> READYSTATE_COMPLETE                                                      'wait for page to load

Loop

Set htmldoc1 = ie.document                                                                              'Document webpage
Set HTMLAs = htmldoc1.getElementsByTagName("a")                                                      'Find all input tags

    For Each HTMLInput In HTMLAs
    'Debug.Print HTMLA.getAttribute("classname"), HTMLA.getAttribute("href"), HTMLA.getAttribute("rel")

    If HTMLInput.getAttribute("href") = "javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar1','V6422')" Then

HTMLInput.Click


    Exit For
    End If

Next HTMLInput

Application.Wait (Now + TimeValue("0.00.02"))

 Set htmldoc2 = ie.document                                                                              'Document webpage
Set HTMLBs = htmldoc2.getElementsByTagName("a")                                                      'Find all input tags

    For Each HTMLInputs In HTMLBs
    'Debug.Print HTMLA.getAttribute("classname"), HTMLA.getAttribute("href"), HTMLA.getAttribute("rel")

    If HTMLInputs.getAttribute("href") = "javascript:__doPostBack('ctl00$ContentPlaceHolder1$Calendar1','6423')" Then

HTMLInputs.Click


    Exit For
    End If

Next HTMLInputs

End Sub




Aucun commentaire:

Enregistrer un commentaire