[FONT="Verdana"][SIZE="1"]Private WithEvents m_wb As SHDocVw.WebBrowser
Private m_param As cSearchParam
'********************************************************************
'* Jun 26 2009
'* Properties>
'*
'********************************************************************
Property Get SearchParam() As cSearchParam
' Custom class that provides search parameters for property searches
If m_param Is Nothing Then Set m_param = New cSearchParam
Set SearchParam = m_param
End Property
'********************************************************************
'* Jun 26 2009
'* Form Events>
'*
'********************************************************************
Private Sub Form_Load()
Set m_wb = Me.WebBrowser0.Object
End Sub
Private Sub Form_Resize()
With Me.WebBrowser0
.Width = Me.InsideWidth
.Height = Me.InsideHeight
End With
End Sub
'********************************************************************
'* Jun 26 2009
'* Methods>
'*
'********************************************************************
Sub StartScrape()
Dim URL As String
URL = "http://www.someurl.com/propertySearch.aspx"
m_wb.Navigate URL
End Sub
'********************************************************************
'* Jun 24 2009
'* Web Browser Events>
'*
'********************************************************************
Private Sub m_wb_DocumentComplete(ByVal pDisp As Object, URL As Variant)
On Error GoTo handler
Dim baseURL As String
'separate query string from the url
baseURL = Split(URL, "?")
'do actions based on the url
Select Case baseURL(0)
Case "http://www.someurl.com/propertySearch.aspx"
'do actions based on the querystring
Select Case baseURL(1)
Case "action=search" 'searching
With pDisp.Document
.getElementById("_ctl0__ctl0_elLocation_elProvinces").Value = 3
.getElementById("_ctl0__ctl0_elLocation_txtCity").Value = Me.SearchParam.CityList
.getElementById("_ctl0__ctl0_elFinancialDetails_elMinPrice").Value = Me.SearchParam.PriceLow
.getElementById("_ctl0__ctl0_elFinancialDetails_elMaxPrice").Value = Me.SearchParam.PriceHigh
.getElementById("_ctl0__ctl0_elBuilding_elBeds").Value = "3-0"
.getElementById("_ctl0__ctl0_elFinancialDetails_elOwnershipType").Value = 1
.getElementById("_ctl0__ctl0_elSortResults_ddlPageSize").Value = 50
.getElementById("_ctl0__ctl0_btnSubmit").Click
End With
Case "action=details" 'property details
With pDisp.Document
.getElementById("txtMlsNumber").Value = m_item.MLS
.getElementById("lnkMlsSearch").Click
End With
End Select
Case "http://www.someurl.com/Disclaimer.aspx"
pDisp.Document.getElementById("_ctl0_lnkAccept").Click
Case "http://www.someurl.com/PropertyResults.aspx"
Select Case "q=listing"
Case 0
ParsePage pDisp.Document.body.innerHTML
DoCmd.Close acForm, Me.Name
End Select
Case "http://www.someurl.com/PropertyDetails.aspx"
Me.Visible = True
End Select
Exit Sub
handler:
App.Log.AddError err, Me, "DocumentComplete()", True
End Sub
'********************************************************************
'* Jun 26 2009
'* Utilities>
'*
'********************************************************************
Private Sub ParsePage(text As String)
On Error GoTo handler
'string processing here to store data from page HTML to tables
Exit Sub
handler:
App.Log.AddError err, Me, "ParsePage()", True
End Sub[/SIZE][/FONT]