Im using VBA (in Access) to scrape an internal webpage at work to gather email addresses. The emails are encoded and i need to use this page to decode them. I can get it to return the entire HTML of a page and within this i need to narrow down and extract the email address.
right now i have this as my code:
[CODE=vb]Private Sub Command0_Click( )
Dim webBrowser As webBrowser
Dim recordset As ADODB.recordset
Dim ScrapeHTML As String
Dim test As String
Set webBrowser = CreateObject("I nternetExplorer .Application")
Set recordset = New ADODB.recordset
recordset.Open "scrambled" , CurrentProject. Connection
With webBrowser
.Navigate "URL removed for security purposes"
.Visible = True
Do While webBrowser.Busy
DoEvents
Loop
End With
Do While webBrowser.Busy
DoEvents
Loop
Do While Not recordset.EOF
Me.[pnr] = recordset![pnr]
Do While webBrowser.Busy
DoEvents
Loop
Debug.Print test
With webBrowser
.Document.Forms ("EncodeDecodeE mailForm").all( "decode").f ocus
.Document.Forms ("EncodeDecodeE mailForm").all( "decode").V alue = recordset![Scrambled email]
SendKeys "{TAB}"
Pause 1
SendKeys "{ENTER}"
Pause 2
Do While webBrowser.Busy
DoEvents
Loop
ScrapeHTML = webBrowser.Docu ment.documentEl ement.innerHTML
ScrapeHTML = Mid(ScrapeHTML, InStr(1, ScrapeHTML, "this.form.enco de") + 112, 60)
Debug.Print ScrapeHTML
ScrapeHTML = Left(ScrapeHTML , InStr(1, ScrapeHTML, "<") - 1)
Debug.Print InStr(1, ScrapeHTML, ">")
Me.[decoded email] = Right(ScrapeHTM L, InStr(1, ScrapeHTML, ">") + 30)
Debug.Print Me.[decoded email]
recordset.MoveN ext
DoCmd.RunComman d acCmdRecordsGoT oNew
End With
Do While webBrowser.Busy
DoEvents
Loop
With webBrowser
.Document.Forms ("EncodeDecodeE mailForm").all( "decode").f ocus
.Document.Forms ("EncodeDecodeE mailForm").all( "decode").V alue = ""
End With
Do While webBrowser.Busy
DoEvents
Loop
Pause 1
Do While webBrowser.Busy
DoEvents
Loop
Loop
End Sub[/CODE]
and my output looks like this:
obviously im not doing something right with my Left(), Right() functions, but i cant seem to figure it out. In fact i think that location of the email address is moving around in the HTML by a few characters every time.
Does anyone have any ideas on how to accomplish this?
right now i have this as my code:
[CODE=vb]Private Sub Command0_Click( )
Dim webBrowser As webBrowser
Dim recordset As ADODB.recordset
Dim ScrapeHTML As String
Dim test As String
Set webBrowser = CreateObject("I nternetExplorer .Application")
Set recordset = New ADODB.recordset
recordset.Open "scrambled" , CurrentProject. Connection
With webBrowser
.Navigate "URL removed for security purposes"
.Visible = True
Do While webBrowser.Busy
DoEvents
Loop
End With
Do While webBrowser.Busy
DoEvents
Loop
Do While Not recordset.EOF
Me.[pnr] = recordset![pnr]
Do While webBrowser.Busy
DoEvents
Loop
Debug.Print test
With webBrowser
.Document.Forms ("EncodeDecodeE mailForm").all( "decode").f ocus
.Document.Forms ("EncodeDecodeE mailForm").all( "decode").V alue = recordset![Scrambled email]
SendKeys "{TAB}"
Pause 1
SendKeys "{ENTER}"
Pause 2
Do While webBrowser.Busy
DoEvents
Loop
ScrapeHTML = webBrowser.Docu ment.documentEl ement.innerHTML
ScrapeHTML = Mid(ScrapeHTML, InStr(1, ScrapeHTML, "this.form.enco de") + 112, 60)
Debug.Print ScrapeHTML
ScrapeHTML = Left(ScrapeHTML , InStr(1, ScrapeHTML, "<") - 1)
Debug.Print InStr(1, ScrapeHTML, ">")
Me.[decoded email] = Right(ScrapeHTM L, InStr(1, ScrapeHTML, ">") + 30)
Debug.Print Me.[decoded email]
recordset.MoveN ext
DoCmd.RunComman d acCmdRecordsGoT oNew
End With
Do While webBrowser.Busy
DoEvents
Loop
With webBrowser
.Document.Forms ("EncodeDecodeE mailForm").all( "decode").f ocus
.Document.Forms ("EncodeDecodeE mailForm").all( "decode").V alue = ""
End With
Do While webBrowser.Busy
DoEvents
Loop
Pause 1
Do While webBrowser.Busy
DoEvents
Loop
Loop
End Sub[/CODE]
and my output looks like this:
Code:
iddle>BOB@COMCAST.NET
Does anyone have any ideas on how to accomplish this?
Comment