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
Bookmarks