I am still trying to learn more about scraping and I could devise a code that enables me to get the desired results.
Here's the code
Sub Test()
Dim e As Variant
Dim ie As Object
Dim ulElem As Object
Dim liElem As Object
Dim anchElem As Object
Dim dt As Date
Dim lDay As Integer
Dim lMnth As Integer
Dim lYear As Integer
Dim r As Long
Set ie = CreateObject("InternetExplorer.Application")
dt = Date - 2
lDay = Day(dt)
lMnth = Month(dt)
lYear = Year(dt)
With ie
.Visible = False
.Navigate "http://www.handelsregisterbekanntmachungen.de/?aktion=suche#Ergebnis"
Do: DoEvents: Loop Until .readyState = 4
For Each e In ie.document.getElementsByTagName("select")
If Len(e.innerText) = 56 Then
e.selectedIndex = lDay
ElseIf Len(e.innerText) = 18 Then
e.selectedIndex = lMnth
ElseIf Left(e.innerText, 8) = "----2000" Then
e.selectedIndex = lYear - 1999
ElseIf InStr(e.innerText, "Alle Bekanntmachungen") > 0 Then
e.selectedIndex = 1
End If
Next e
For Each e In ie.document.getElementsByTagName("input")
If e.Value = "Suche starten" Then e.Click: Exit For
Next e
Do: DoEvents: Loop Until .readyState = 4
Application.Wait Now() + TimeValue("00:00:05")
If InStr(ie.document.body.innerHTML, "Es wurden 0 Treffer gefunden.") > 0 Then
MsgBox "No Results Found", vbExclamation: Exit Sub
Else
For Each ulElem In ie.document.getElementsByTagName("b")
For Each liElem In ulElem.getElementsByTagName("li")
Set anchElem = liElem.getElementsByTagName("a")
If anchElem.Length > 0 Then
r = r + 1
Cells(r, 1) = Mid(anchElem.Item(0).innerText, 11)
End If
Next liElem
Next ulElem
End If
End With
End Sub
But as a matter of trying to learn more about XMLHTTP requests I am seeking for a way to get the same results but without using IE. so I think using XMLHTTP will be more efficient specially I could see post data after setting up the desired choices for the search process.
Take a look at the below example: