+ Reply to Thread
Results 1 to 9 of 9

Extract details from web portal with looping criteria

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-03-2011
    Location
    India
    MS-Off Ver
    Excel 2015
    Posts
    122

    Unhappy Extract details from web portal with looping criteria

    Roll Number Example : 500001 , 500002,500002,500003,500004,500005,500006,500007,500008

    I have website where i need to enter the numeric value and after submit -- the details of information comes out which i would need the information to capture as below.

    REGISTRATION NO 500001 CANDIDATE NAME A HOSAMANIKENDAPPA

    Roll Number ; 500006 - should show as it is come as in page (Please check the registration number and try again)
    Loop/ Countering the roll number and capturing the results are my issues which is getting trouble.
    Last edited by yogananda.muthaiah; 12-30-2012 at 09:57 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Extract details from web portal with looping criteria

    Hello yogananda.muthaiah,

    The macros below have been added to the attached workbook. There is button at the top of the sheet to run extract the details from the web page. The registration numbers are in column "A". The macro will loop through each cell in column "A" that has a registration number and place the details in column "A" of the same row.

    Macro to Extract Web Data
    Sub GetDetails()
    
        Dim Cell As Range
        Dim Doc As Object
        Dim DocInputs As Object
        Dim ieApp As Object
        Dim Paragraphs As Object
        Dim ResultsURL As String
        Dim Rng As Range
        Dim RngEnd As Range
        Dim Tables As Object
        Dim URL As String
        Dim wndShell As Object
        
            Set Rng = Range("A2")
            Set RngEnd = Cells(Rows.Count, Rng.Column).End(xlUp)
            
            If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Range(Rng, RngEnd)
            
            Set wndShell = CreateObject("Shell.Application").Windows
            Set ieApp = CreateObject("InternetExplorer.Application")
            
                URL = "http://karresults.nic.in/indexPUC2012sup.htm"
                ResultsURL = "http://karresults.nic.in/resPUC2012sup.asp"
                
                ieApp.Navigate URL
                
                While wndShell(wndShell.Count - 1).Name <> "Windows Internet Explorer": DoEvents: Wend
                
                For Each Cell In Rng
                    Set Doc = ieApp.Document
                    
                    Set DocInputs = Doc.getElementsBytagName("input")
                    DocInputs(0).Value = Cell
                    DocInputs(1).Click
                    
                    While ieApp.LocationURL <> ResultsURL: DoEvents: Wend
                    
                    Set Doc = ieApp.Document
                    
                    Set Tables = Doc.getElementsBytagName("table")
                    
                    If Tables.Length > 1 Then
                        With Tables(1).Rows(0)
                            Details = .Cells(0).innerHTML & " " & .Cells(1).innerHTML & " " _
                                    & .Cells(2).innerHTML & " " & .Cells(3).innerHTML
                        End With
                        Cell.Offset(0, 1) = RemoveTags(Details)
                    Else
                        Set Paragraphs = Doc.getElementsBytagName("p")
                        Cell.Offset(0, 1) = Paragraphs(4).innerHTML
                    End If
                    
                    ieApp.GoBack
                Next Cell
                    
            ieApp.Quit
                
    End Sub
    Code to Remove HTML Tags from Text
    Function RemoveTags(ByVal Text As String) As String
    
        Dim RegExp As Object
        
            Set RegExp = CreateObject("VBScript.RegExp")
            
                RegExp.Global = True
                RegExp.Pattern = "\<.*\>"
                
            RemoveTags = RegExp.Replace(Text, "")
                
    End Function
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Extract details from web portal with looping criteria

    Another way - using as a worksheet function:
    Public Function GetCandidate(idRef As String) As String
        
        Dim oHtm As Object: Set oHtm = CreateObject("htmlfile")
        Dim oTables As Object
        
        With CreateObject("msxml2.xmlhttp")
            .Open "POST", "http://karresults.nic.in/resPUC2012sup.asp", False
            .setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
            .send "reg=" & idRef & _
                    "&B1=Submit"
            oHtm.body.innerhtml = .responsetext
        End With
        
        Set oTables = oHtm.getelementsbytagname("table")
        If oTables.Length > 1 Then
            GetCandidate = oTables(1).innerText
        Else
            GetCandidate = "Please Check Again"
        End If
        
    End Function
    Assuming CandidateNumber in A1
    PHP Code: 
    =GetCandidate(A1

  4. #4
    Forum Contributor
    Join Date
    04-03-2011
    Location
    India
    MS-Off Ver
    Excel 2015
    Posts
    122

    Re: Extract details from web portal with looping criteria

    Thank you Leith & Kyle for your outstanding work. Happy Christmas to u all and enjoy your holidays.

    could you pls try this site with selecting radio button 2008-09 Search and Application No. entered as 1 and clicking search to get my results out in excel




    PHP Code: 
    Application No    Owner Name    PID No    Ward Name    Ward No
    1    P
    .S.KHASIM    69-28-68    Neelasandra    69
    1    
    (1MOHAMMED YOUSUF (2MOHAMMED ARSHAD (3MOHAMMED RIYAZ    98-149-65    GANGANAGAR    98
    1    j m murthy         YELAHANKA    804
    1    S R LAKSHMI         KENGERI    603
    1    SFAADF         KONANAKUNTE    504
    1    RAJESH ANGADI         MARATHALLI    902 
    Last edited by yogananda.muthaiah; 12-30-2012 at 09:58 AM. Reason: AQ

  5. #5
    Forum Contributor
    Join Date
    04-03-2011
    Location
    India
    MS-Off Ver
    Excel 2015
    Posts
    122

    Re: Extract details from web portal with looping criteria

    Hi leith & Kyle,

    tried to make some changes in below codes provided for my 2nd site provided but radio button option making me iritate.

    give me a hints.

  6. #6
    Forum Contributor
    Join Date
    04-03-2011
    Location
    India
    MS-Off Ver
    Excel 2015
    Posts
    122

    Re: Extract details from web portal with looping criteria

    Hi Kyle, Leith

    Waiting for your hints.... Others welcome your thoughts

  7. #7
    Forum Contributor
    Join Date
    04-03-2011
    Location
    India
    MS-Off Ver
    Excel 2015
    Posts
    122

    Re: Extract details from web portal with looping criteria

    Hi,

    Anyone get me a hint to solve this issue for #4 comments

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,239

    Re: Extract details from web portal with looping criteria

    I think you should start a new thread for this one. It's an entirely different site and problem.

    You also haven't mentioned whether the proposed solutions work for your first site

  9. #9
    Forum Contributor
    Join Date
    04-03-2011
    Location
    India
    MS-Off Ver
    Excel 2015
    Posts
    122

    Re: Extract details from web portal with looping criteria

    Thank you Kyle .

    1st site works fine and thanks to u both (Leith) . We will start a new thread for 2nd site.

    Advance wishes for coming New year 2013 ahead and success goes in every step of u all.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1