I've written a script using vba in combination with IE to parse the contact information from a webpage applying regex on it. I searched a lot but could not find any example that can satiate my requirement. The pattern
may not be ideal to find the phone
number but the main concern here is how I can use the pattern
within vba IE.
Once again: my intention here is to parse the phone number 661-421-5861
from that webpage applying regex
within vba IE.
This is what I've tried so far:
Sub FetchItems()
Const URL$ = "https://www.nafe.com/bakersfield-nafe-network"
Dim IE As New InternetExplorer, HTML As HTMLDocument
Dim rxp As New RegExp, email As Object, Row&
With IE
.Visible = True
.navigate URL
While .Busy = True Or .readyState < 4: DoEvents: Wend
Set HTML = .document
End With
With rxp
.Pattern = "(?<=Phone:)\s*?.*?([^\s]+)"
Set email = .Execute(HTML.body.innerText) 'I'm getting here an error
If email.Count > 0 Then
Row = Row + 1: Cells(Row, 1) = email.Item(0)
End If
End With
IE.Quit
End Sub
When I execute the above script I encounter an error method "Execute" of object "IRegExp2" failed when it hits the line containing Set email = .Execute(HTML.body.innerText)
. How can I make it a go successfully?
Contact:
string. Maybe you should log in first. – Wiktor StribiżewContact:
within the pattern. – SIM