This is how I'd do it, trying to parse HTML with regex is like trying to eat soup with a fork, it just can't cope with the complexities of html (and xml), so I'd use the ie object library. Note the below requires IE 9, as I don't believe .getElementbyClassName is available in earlier versions; also you'll see there is no need to open ie, we just use it's object library. You say that you already have the source in a string, but I don't so I've included getting the string in the below. You should be able to adapt the below, essentially we create a htmldocument directly from a string (in my case the result of the xml call) in yours probably your existing string; we then loop through it's "rows" which is a collection of elements with the same class name, since all your data is nested in these rows, we can then loop through each row's children to extract the data.
This data is written to an array and then dumped into sheet 2 starting at "A1"
Note: You will need to set a reference to the Microsoft HTML Object Library
Sub testhtml()
Dim htmlFile As HTMLDocument
Dim rowCount As Long
Dim orow As Object
Dim data() As String
Dim x as Long
With CreateObject("MSXML2.XMLHTTP")
.Open "GET", "http://fortcollins.craigslist.org/search/?areaID=287&subAreaID=&query=Excel&catAbb=sss"
.send
Do: DoEvents: Loop Until .readystate = 4
Set htmlFile = New HTMLDocument
htmlFile.body.innerHTML = .responseText
.abort
End With
With htmlFile
rowCount = .getElementsByClassName("row").Length
ReDim data(1 To rowCount, 1 To 10)
x = 1
For Each orow In .getElementsByClassName("row")
data(x, 1) = orow.Children(0).ID
data(x, 2) = orow.Children(1).innerText
data(x, 3) = orow.Children(2).innerText
data(x, 4) = orow.Children(3).href
data(x, 5) = orow.Children(3).innerText
data(x, 6) = orow.Children(4).innerText
data(x, 7) = orow.Children(5).innerText
data(x, 8) = orow.Children(6).innerText
data(x, 9) = orow.Children(7).innerText
data(x, 10) = orow.Children(8).innerText
x = x + 1
Next orow
End With
Sheet2.Cells(1, 1).Resize(rowCount, 10).Value = data
End Sub
Let me know if it does what you are looking for
Bookmarks