View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.programming
Norie Norie is offline
external usenet poster
 
Posts: 82
Default Parse HMTL source to fill in cells?

Jason

I'm not quite sure what you are asking and it seems actually be more to do
with inserting
dates into a worksheet.

The code I posted assumes you have dates starting in row 2, column A.

It goes down the column, gets the data, inserts it in the relevant columns
(B,C and D) and then
moves on.

It stops when a blank cell is found.

So in theory if you have all the dates you want, in whatever order it should
work.

If you need help filling in dates there are various ways to do that but they
really depend on what you've currently
got and what you want to end up with.

Perhaps a topic for another thread.

As for just getting the number, shouldn't be a problem - I'll see if I can
do something.

Would you like it in Fahrenheit or Celsius?:)

PS If you just need the number for calculations then you could probably do
that without
code, a simple formula should suffice.

"Jason" wrote in message
...
Norie,

Thanks, that did it. How can I get it to enter just the number, say "85"
instead of "85 <degree signF"? I know that is simple, but I'm still
learning.

I changed
Set rng = ws.Range("A2")
to something similar to Joel's post
RowCount = 1
Set rng = ws.Range("A" & RowCount)
RowCount = RowCount + 1
so that I can enter in a whole list of dates and have it go through and do
it for all the dates listed.

Of course, now my mind is going...

Any idea how I could have it look at the table, find the last date listed
in
column A, enter the next date below it, and fill in all the dates up to
present day minus 1? Meaning from the last date until "yesterday". Of
course
"yesterday" would depend on when it is run.

This way, we could run the script to fill in all our missing data

"Norie" wrote:

Jason

Something like this perhaps?

Private Sub MaxMinMeanTemps()

Dim IE As Object
Dim doc As Object
Dim tbls As Object
Dim tbl As Object
Dim tblData As Object
Dim tblRow As Object
Dim rwCells As Object
Dim ws As Worksheet
Dim rng As Range
Dim strDate As String
Dim strURL As String
Dim I As Long

Set ws = Worksheets(1)

Set rng = ws.Range("A2")

Set IE = CreateObject("InternetExplorer.Application")

IE.Visible = True

While rng.Value < ""

strDate = Year(rng.Value) & "/" & Month(rng.Value) & "/" &
Day(rng.Value)

strURL = "http://www.wunderground.com/history/airport/KNYC/" &
strDate & "/DailyHistory.html"

IE.Navigate strURL

Do While IE.Busy: DoEvents: Loop
Do While IE.ReadyState < 4: DoEvents: Loop

Set doc = IE.Document

Set tbls = doc.getElementsByTagName("TABLE")

For Each tbl In tbls
If tbl.className = "dataTable tm10" Then
Set tblData = tbl
Exit For
End If
Next

For I = 2 To 4

Set tblRow = tblData.Rows(I)

Set rwCells = tblRow.Cells

rng.Offset(, I - 1) = rwCells(1).innertext

Next I

Set rng = rng.Offset(1)

Wend

IE.Quit: Set IE = Nothing

End Sub

"Jason" wrote in message
...
Sorry if I was too ambiguous with my original post...

This HTML source is from the following webpage on temperature data.
http://www.wunderground.com/history/...tory.html?MR=1

In this case, it is for NYC on July 2, 2008 (from the
...NYC/2008/7/2/...
in
the address)
85 is the Max temperatue
76 is the mean
67 is the low temperature.

Essentially we want to setup a process to
1. look up the date in column A
2. go the website and parse the data for that date
3. enter the max in column B, low in column C, mean in column D
4. then repeat this process for the next date in the next row

Hopefully this helps.


"Jason" wrote:

I'm a newbie with VBA, but want to automate a procedure we are doing.

How would I write a function to look at the following HTML source:

'<td<a
href="/history/airport/KNYC/2008/7/2/DailyHistory.html"2</a</td
' <td class="bl gb"
' 85
'</td
' <td class="gb"
' 76
'</td
' <td class="br gb"
' 67
'</td

And put the 85 into cell B1, 76 into B2, 67 into B3?

Thanks!