View Full Version : Challenging VBA Web scraping coding

04-09-2015, 03:08 PM
Hi everyone,
I am doing new project and now am stuck.
I need to grab data from search results ( Titles and links ).
Website:Australian Taxation Office
Here is my code.

Sub new_idea1()
Dim ie As Object
Dim navtar As String
Dim elemCollection As Object
Dim URL As Object
Dim i As Long 'i is our div counter
Dim j As Long 'j is our post-title div counter

Set ie = CreateObject("InternetExplorer.Application")

With ie
.Visible = True
navtar = Sheet1.Range("C3").Value
.Navigate navtar
waitTime = 5
Start = Timer
While ie.busy 'Basically just a loading check
ie.document.getElementsbyName("txt_banner_field").Item.innerText = Sheet1.Range("B3") ' add word for search
Do While ie.busy: DoEvents: Loop
Set elemCollection = .document.Length.getElementsByTagName("div")
i = 0
j = 0
While i < elemCollection.Length And j < 10
If elemCollection(i).className = "resultTitle" Then
URL = elemCollection(i).innerHTML 'Trimming
URL = Right(URL, Len(URL) - InStr(URL, Chr(34))) 'Trimming
URL = Left(URL, InStr(URL, Chr(34)) - 1) 'Trimming
Sheet3.Range("A" & i) = URL
j = 1 + 1

End If
i = i + 1
End With
' cleaning up memory
Set ie = Nothing

End Sub

Currently, code does search , but I cannot pull results from the search to the worksheet.
Can anyone help with it?