babulalgandhi
New Member
- Joined
- Feb 5, 2015
- Messages
- 12
Hi Friends
The Website "http://www.newkerala.com/pincode/" Is For To Get Place Name From Postal Code
I Made A Macro Which Ask For Pincode And Get Data From Website.
The Result Is In Three Or Four Pages Vary As Per Pincode Input
I Can Get First Page Result Data In Excel From Web Page.
Dont Know How To Implement Code In Excel Macro
To Navigate Next Page And Get Data And Navigate Next Page And Get Data And So On
Here Is My Code Friends
Sub getaddress()
'we define the essential variables
Dim ie As Object
Dim r As Integer, c As Integer, t As Integer
Dim elemCollection As Object
Dim form As Variant, button As Variant
'add the "Microsoft Internet Controls" reference in your VBA Project indirectly
Set ie = CreateObject("InternetExplorer.Application")
'more variables for the inputboxes - makes our automation program user friendly
mypincode = InputBox("Enter Pincode")
With ie
.Visible = True
.navigate ("http://www.newkerala.com/pincode/")
' we ensure that the web page downloads completely before we fill the form automatically
While ie.ReadyState <> 4
DoEvents
Wend
'assigning the vinput variables to the html elements of the form
ie.Document.getElementsByName("keyword").Item.innerText = mypincode
' accessing the button via the form
ie.Document.getElementsByName("Submit2").Item.Click
' again ensuring that the web page loads completely before we start scraping data
Do While ie.busy: DoEvents: Loop
'Clearing any unnecessary or old data in Sheet1
ThisWorkbook.Sheets("Sheet1").Range("A1:K500").ClearContents
Set elemCollection = ie.Document.getElementsByTagName("TABLE")
For t = 0 To (elemCollection.Length - 1)
For r = 0 To (elemCollection(t).Rows.Length - 1)
For c = 0 To (elemCollection(t).Rows(r).Cells.Length - 1)
ThisWorkbook.Worksheets(1).Cells(r + 1, c + 1) = elemCollection(t).Rows(r).Cells(c).innerText
Next c
Next r
Next t
End With
' cleaning up memory
Set ie = Nothing
End Sub
Example Pincodes Are Given Below
110001
110002
110003
110004
110005
110006
110007
110008
110009
110010
The Result Is In Three Or Four Pages Vary As Per Pincode Input
I Can Get First Page Result Data In Excel From Web Page.
Dont Know How To Implement Code In Excel Macro
To Navigate Next Page And Get Data And Navigate Next Page And Get Data And So On
Thanks You For Your Time Spent On Me Helping
Thanks & Regards
Babulal Gandhi
babulalgandhi@gmail.com
The Website "http://www.newkerala.com/pincode/" Is For To Get Place Name From Postal Code
I Made A Macro Which Ask For Pincode And Get Data From Website.
The Result Is In Three Or Four Pages Vary As Per Pincode Input
I Can Get First Page Result Data In Excel From Web Page.
Dont Know How To Implement Code In Excel Macro
To Navigate Next Page And Get Data And Navigate Next Page And Get Data And So On
Here Is My Code Friends
Sub getaddress()
'we define the essential variables
Dim ie As Object
Dim r As Integer, c As Integer, t As Integer
Dim elemCollection As Object
Dim form As Variant, button As Variant
'add the "Microsoft Internet Controls" reference in your VBA Project indirectly
Set ie = CreateObject("InternetExplorer.Application")
'more variables for the inputboxes - makes our automation program user friendly
mypincode = InputBox("Enter Pincode")
With ie
.Visible = True
.navigate ("http://www.newkerala.com/pincode/")
' we ensure that the web page downloads completely before we fill the form automatically
While ie.ReadyState <> 4
DoEvents
Wend
'assigning the vinput variables to the html elements of the form
ie.Document.getElementsByName("keyword").Item.innerText = mypincode
' accessing the button via the form
ie.Document.getElementsByName("Submit2").Item.Click
' again ensuring that the web page loads completely before we start scraping data
Do While ie.busy: DoEvents: Loop
'Clearing any unnecessary or old data in Sheet1
ThisWorkbook.Sheets("Sheet1").Range("A1:K500").ClearContents
Set elemCollection = ie.Document.getElementsByTagName("TABLE")
For t = 0 To (elemCollection.Length - 1)
For r = 0 To (elemCollection(t).Rows.Length - 1)
For c = 0 To (elemCollection(t).Rows(r).Cells.Length - 1)
ThisWorkbook.Worksheets(1).Cells(r + 1, c + 1) = elemCollection(t).Rows(r).Cells(c).innerText
Next c
Next r
Next t
End With
' cleaning up memory
Set ie = Nothing
End Sub
Example Pincodes Are Given Below
110001
110002
110003
110004
110005
110006
110007
110008
110009
110010
The Result Is In Three Or Four Pages Vary As Per Pincode Input
I Can Get First Page Result Data In Excel From Web Page.
Dont Know How To Implement Code In Excel Macro
To Navigate Next Page And Get Data And Navigate Next Page And Get Data And So On
Thanks You For Your Time Spent On Me Helping
Thanks & Regards
Babulal Gandhi
babulalgandhi@gmail.com
Last edited: