Ron,
No worries, thanks!
Yeah, you are right about the un-unique identifiers. I am trying to come up
with a way to iterate the code below for each date then look for those
identifiers. I will take a look at the original link you sent a while back
on the IE Object.
<td><a href="/history/airport/KHOU/2008/9/1/DailyHistory.html">1</a></td>
<td class="bl gb">
91
</td>
<td class="gb">
84
</td>
<td class="br gb">
76
</td>
At least in a single test, I believe the following modifications will uniquely
identify the required segments. I suspect there are easier ways to do this,
but ...
Note that I changed the pattern; I also changed the RegexMid function and added
some "clean-up" to both the main Sub and the private Sub.
(If you don't explicitly quit IE, you wind up with multiple IE processes
running; and it will eventually crash. In some other program, the limit was
about sixteen).
Anyway try this:
====================================
Option Explicit
Sub getCityTemps()
Dim AirCode As Range, ACrng As Range
Dim c As Range, rng As Range
Dim j As Long
Dim sURLairport As String
Dim myStr As String
Dim test As Variant
Dim Val As Variant
Dim IE As Object
'Set ACrng = Sheets("City_Airport").Range("B2:B26")
'For Each AirCode In ACrng
' sURLairport = AirCode
Const sURL1 As String = _
"
http://www.wunderground.com/history...009&req_city=NA&req_state=NA&req_statename=NA"
'Const sURL2 As String = "/"
Dim sURLdate As String
'Const sURL3 As String = "/DailyHistory.html?MR=1"
Application.Cursor = xlWait
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate sURL1
While IE.ReadyState <> 4
DoEvents
Wend
myStr = IE.Document.body.innerhtml
Set rng = Range("A2").CurrentRegion
Set rng = rng.Resize(rng.Rows.Count, 1)
For Each c In rng
sURLdate = Format(c.Value2, "yyyy/m/d")
c.Offset(0, 1).Value = RegexMid(myStr, sURLdate, "bl gb")
c.Offset(0, 2).Value = RegexMid(myStr, sURLdate, "br gb")
c.Offset(0, 3).Value = RegexMid(myStr, sURLdate, "class=gb")
Next c
'i = i + 3
'Next AirCode
IE.Quit
Set IE = Nothing
Application.Cursor = xlDefault
End Sub
Private Function RegexMid(s As String, sDate As String, sTempType As String) _
As String
Dim re As Object, mc As Object
Set re = CreateObject("vbscript.regexp")
re.IgnoreCase = True
re.MultiLine = True
re.Global = True
re.Pattern = "\b" & sDate & "/DailyHistory[\s\S]+?" & sTempType _
& "\D+(\d+)"
If re.test(s) = True Then
Set mc = re.Execute(s)
RegexMid = mc(0).submatches(0)
End If
Set re = Nothing
End Function
====================================
--ron