Can It Be Done?!

  • Thread starter Thread starter grant464
  • Start date Start date
G

grant464

Guest
Hi folks,

I am looking to make an Access Database for which weather data is retrieved from a government website and stored in the database for manipulation.

Can this can be done? What kind of technologies could make this task possible (I would assume Access wouldn't be able to do it all on its own)?

The technology would need to pick the data out amongst the HTML code. Here is a link to a likely datasheet: Daily Weather Sheet

Any discussion would be greatly appreciated, thanks guys,

Grant
 
Well..., if you want some blue-sky type of discussion, some crazy ideas about how to do this reasonably...

Read up on Application Objects. Also look in the help files for IE and Word on the subject of VBA, which will contain discussions of what objects each application object exposes to automation.

I have NO experience in directly mucking about in HTML and I don't know if IE will cooperate, but...

If you could give IE the name of the page you want (and generate the options such as date, province, etc. as part of the URL), you could get the page "up" - at which time you could tell IE to save the page as HTML.

Step two would be to open a Word Application Object, open the HTML, and do a SaveAs to a Word document. (What I'm hoping is that you can get it to convert that HMTL table into a Word table.) Close the HTML version and round-file it. (Kill filespec should do the trick nicely.)

Step three would be to open the saved Word document and use Automation to read the table directly. To do this, you need to know that Word tables are part of the Component Object Model and are well-behaved.

A document is a member of word's Documents collection. You have a shortcut name available, I think CurrentDocument, when you select a given document. A table is a member of a document's Tables collection. You can access it via numbers or create a Table object in VBA and do a Set-class operation. Set myTable=CurrentDocument.Tables(2) or something like that.

Now, within a table, you have a collection of rows. So to get to a particular row you can do myTable.Rows(2). That's the 2nd row because they are one-based, not zero-based. Then finally, each column in a row is actually called a Cell and is part of the Cells collection for that row.

So you could make a reference that looked like

WordObject.Documents(1).Tables(2).Rows(3).Cells(4) to see the 4th column of the third row of the second table of the first document opened through your word application object. Which is the basis for a really simple loop stepping through the rows and cells (columns) via For-loops.

Now, this is a POSSIBLE approach and it depends on the automated down-load through IE and also on the conversion of the HTML to a Word Document. But if IE cooperates and Word cooperates, it is not impossible to do as a monolithic operation.

You might also try this directly to see if there are any tables in the HTML document, in which case you could omit the conversion step... but since I've never worked on inputting an HTML page before, I'm not going to swear what is available.

Now, how do you find out what is possible? Try it. In debug mode, try first to open an IE object so you can browse. Once the object is open, see what it has in it. I.e. in the debug window, examine the object and open the tree diagram that shows its component collections. If you can load the URL, do so and see what becomes available. Now play with that to see if you can do a SaveAs.

Next, if you have the saved HTML, open it in Word and see what it gives you in the way of collections. If there is a tables collection, you can look at the rows collection and then at the cells collection within a row to see what is in each cell. (The .Value property holds the text/string if there is one.)

It is tedious as hell to do this, but the GOOD news is that you learn a lot by peeking "behind the veil" at each step of the way. And when you are done, you have a far better handle on what is or is not possible.

You asked for discussion. I gave you a theoretical discussion because of a lack of experience in the HTML portion. BUT once you get it into Word, that part IS based on experience. So it is not entirely blue-sky.

Good luck.
 
Last edited:
Thanks

Thanks for the indepth discussion, I am going to look into those points and see where it gets me towards a solution. I actually never thought to use Microsoft Office for the entire process.

My next thought is to use a locally hosted PHP or ASP script that when called on, grabs the info from the web and throws it into the database (I am modestly knowledgable in PHP so I wouldn't have as large of a handy cap when coding the solution). I am going to investigate the capabilities of PHP and see where it takes me. However, the downside to this is that getting PHP installed on a local server could become a problem.

Any other suggestions by you guys would be great!

thanks,

Grant
 
this is the start of the data:


<table id="dataTable"

so after you have VB save the page and open it for editing, you would look for that, and start to parse with SQL for each row after that adding records to a table.

not too hard if you figure out the parsing part.

Code:
<table id="dataTable" cellspacing="1"><tr id="dataTableHeaderRow"><th id="dataTableColHeader" colspan="11">Hourly Data Report for January 13, 2004</th></tr><tr id="dataTableEvenRow"><th id="dataTableColHeader">T<br>i<br>m<br>e</th><th id="dataTableColHeader"><a href="javascript:target_window('../Glossary-popup_e.html#temp');"><abbr title="Temperature">Temp</abbr></a><br>°C<br><a href="generate_chart_e.html?timeframe=1&Prov=XX&StationID=4932&Year=2004&Month=1&Day=13&Type=line&MeasTypeID=temp"><img border="0" src="../images/gi-chart.gif"></a></th><th id="dataTableColHeader"><a href="javascript:target_window('../Glossary-popup_e.html#dptemp');"><abbr title="Dew Point Temperature">Dew Point Temp</abbr></a><br>°C<br><a href="generate_chart_e.html?timeframe=1&Prov=XX&StationID=4932&Year=2004&Month=1&Day=13&Type=line&MeasTypeID=dptemp"><img border="0" src="../images/gi-chart.gif"></a></th><th id="dataTableColHeader"><a href="javascript:target_window('../Glossary-popup_e.html#relhum');"><abbr title="Relative Humidity">Rel Hum</abbr></a><br>%<br><a href="generate_chart_e.html?timeframe=1&Prov=XX&StationID=4932&Year=2004&Month=1&Day=13&Type=line&MeasTypeID=relhum"><img border="0" src="../images/gi-chart.gif"></a></th><th id="dataTableColHeader"><a href="javascript:target_window('../Glossary-popup_e.html#winddir');"><abbr title="Wind Direction">Wind Dir</abbr></a><br>10's deg<br></th><th id="dataTableColHeader"><a href="javascript:target_window('../Glossary-popup_e.html#windspd');"><abbr title="Wind Speed">Wind Spd</abbr></a><br>km/h<br><a href="generate_chart_e.html?timeframe=1&Prov=XX&StationID=4932&Year=2004&Month=1&Day=13&Type=line&MeasTypeID=windspd"><img border="0" src="../images/gi-chart.gif"></a></th><th id="dataTableColHeader"><a href="javascript:target_window('../Glossary-popup_e.html#visibility');"><abbr title="Visibility">Visibility</abbr></a><br>km<br><a href="generate_chart_e.html?timeframe=1&Prov=XX&StationID=4932&Year=2004&Month=1&Day=13&Type=line&MeasTypeID=visibility"><img border="0" src="../images/gi-chart.gif"></a></th><th id="dataTableColHeader"><a href="javascript:target_window('../Glossary-popup_e.html#stnpress');"><abbr title="Station Pressure">Stn Press</abbr></a><br>kPa<br><a href="generate_chart_e.html?timeframe=1&Prov=XX&StationID=4932&Year=2004&Month=1&Day=13&Type=line&MeasTypeID=stnpress"><img border="0" src="../images/gi-chart.gif"></a></th><th id="dataTableColHeader"><a href="javascript:target_window('../Glossary-popup_e.html#humidex');"><abbr title="Humidex">Hmdx</abbr></a><br><br></th><th id="dataTableColHeader"><a href="javascript:target_window('../Glossary-popup_e.html#windchill');"><abbr title="Wind Chill">Wind Chill</abbr></a><br><br></th><th id="dataTableColHeader"><a href="javascript:target_window('../Glossary-popup_e.html#weather');"><abbr title="Weather">Weather</abbr></a><br><br></th></tr><tr id="dataTableOddRow"><td id="dataTableRowHeader">00:00</td><td id="dataTableRowData">  -1.1 </td><td id="dataTableRowData">  -1.9 </td><td id="dataTableRowData"> 94 </td><td id="dataTableRowData"> 21</td><td id="dataTableRowData"> 26 </td><td id="dataTableRowData">  8.0 </td><td id="dataTableRowData"> 98.37 </td><td id="dataTableRowData"></td><td id="dataTableRowData">  -7 </td><td id="dataTableRowText">Freezing Drizzle, Snow</td></tr></table>

Thats one line of data within that page.

So you would have to parse each section...
 
Last edited:

Users who are viewing this thread

Back
Top Bottom