473,385 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Parse from HTML to Access

1
Hi, I found and adjusted some code (VBA) to parse an HTML file into an access table. It is working fine but the HTML has some information which is enclosed in <div> and therefore not part of the HTML table which I need to store in my access table. This is the code I have:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command5_Click()
  2.  
  3. Dim rawHtml As String, tableChunk As String, tempFile As String
  4.     Dim tmpAt As Long, tableStart As Long, tableEnd As Long
  5.  
  6.     rawHtml = GetPage(Me.webadd)
  7.  
  8.     ' Search forward until we're just before the table we want
  9.     tmpAt = InStr(1, rawHtml, "<div class=""reservation-info"">")
  10.     'tmpAt = InStr(tmpAt, rawHtml, "<div class=""tableSection"">")
  11.  
  12.     ' Get the index of the start of the opening <table> tag
  13.     tableStart = InStr(tmpAt, rawHtml, "<div class")
  14.  
  15.     ' Get the index of the end of the closing </table> tag
  16.     tmpAt = InStr(tableStart, rawHtml, "</table")
  17.     tableEnd = InStr(tmpAt, rawHtml, ">")
  18.  
  19.     ' Extract the table
  20.     tableChunk = Mid(rawHtml, tableStart, tableEnd - tableStart + 1)
  21.  
  22.     ' Use native VBA file I/O
  23.     tempFile = "C:\temp\tempTable.html"
  24.     Open tempFile For Output As #1
  25.     Write #1, tableChunk
  26.     Close #1
  27.  
  28.     ' Import the file to a table
  29.     DoCmd.TransferText acImportHTML, , "T_SQLTYPES", tempFile, True
  30. 'test from here
  31.  
  32. Dim ie As InternetExplorer
  33. 'to refer to the HTML document returned
  34. Dim html As HTMLDocument
  35. 'open Internet Explorer in memory, and go to website
  36. Set ie = New InternetExplorer
  37. ie.Visible = True
  38. ie.Navigate "file:///C:/temp/tempTable.html"
  39. 'show text of HTML document returned
  40. Set html = ie.Document
  41. 'close down IE and reset status bar
  42. Set ie = Nothing
  43. 'Application.StatusBar = ""
  44. Dim QuestionList As IHTMLElement
  45. Set QuestionList = html.getElementsByName("reservation-info")
  46.  
  47.  
  48.  
  49. Me.Text3.Value = QuestionList
  50. Me.Requery
  51. Me.Refresh
  52.  
  53.  
  54.     ' Delete the temp file
  55.     'Kill tempFile
  56.     DoCmd.OpenTable ("T_SQLTYPES")
  57. End Sub
  58.  
All I want for now is to display an item enclosed in <div> in my HTML on Text3 textbox in my form -or better still include it in my table T_SQLTYPES. Here is my HTML code:

Expand|Select|Wrap|Line Numbers
  1. "<div class=""reservation-info"">
  2.         Name of Hotel · #603439460
  3.     </div>
  4.  
  5. </div> <!-- /span12 -->
  6.  
  7. </div> <!-- /row -->
  8.  
  9.  
  10.  
  11.  
  12. <div class=""row-fluid"">
  13.  
  14. <div class=""span6"">
  15.  
  16. <table class=""table table-condensed table-striped table-hover table-bordered table-darkheader"">
  17.  
  18.     <tr>
  19.         <th colspan=""3"" class=""booking-room"">Room 1</th>
  20.     </tr>
  21.  
  22.  
  23.  
  24.     <tr>
  25.         <td><b>Guest name</b></td>
  26.         <td>
  27.             <strong>
  28.                 Mr XXX
  29.             </strong>
  30.         </td>
  31.     </tr>
  32.     <tr><td>Checkin</td><td>14-05-2014</td></tr>
  33.     <tr><td>Checkout</td><td>25-05-2014</td></tr>
  34.  
  35.     <tr>
  36.         <td>Room type</td>
  37.         <td>
  38.             Double or Twin Room - Single Use
  39.         </td>
  40.     </tr>
  41.  
  42.     <tr>
  43.         <td>Number of persons</td>
  44.         <td>
  45.             1 
  46.         </td>
  47.     </tr>
  48.  
  49.  
  50.  
  51.  
  52. <tr>
  53.     <td>Arrival</td>
  54.     <td>
  55.  
  56.         Wednesday, May 14, 2014
  57.  
  58.     </td>
  59. </tr>
  60. <tr>
  61.     <td>Departure</td>
  62.     <td>
  63.  
  64.         Sunday, May 25, 2014
  65.  
  66.     </td>
  67. </tr>
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.     <tr>
  75.         <td>Number of nights</td>
  76.         <td>
  77.             11
  78.         </td>
  79.     </tr>
  80.  
  81.     <tr>
  82.         <td>
  83.             Total costs
  84.             (based on Single Use)
  85.         </td>
  86.         <td>
  87.             EUR xxx
  88.  
  89.  
  90.  
  91.             <br>7 % VAT is included.
  92.  
  93.  
  94.         </td>
  95.     </tr>
  96.  
  97.     <tr>
  98.         <td>Costs per night</td>
  99.         <td>
  100.         18.80
  101.         </td>
  102.     </tr>
  103.  
  104.  
  105.     <tr>
  106.         <td>Costs per night for more than 1 person</td>
  107.         <td>
  108.  
  109.         </td>
  110.     </tr>
  111.  
  112.  
  113.     <tr>
  114.         <td>Status</td>
  115.         <td>
  116.             ok
  117.  
  118.         </td>
  119.     </tr>
  120.  
  121.     <tr>
  122.         <td>Smoking preference</td>
  123.         <td>
  124.             non-smoking
  125.         </td>
  126.     </tr>
  127.  
  128.  
  129.  
  130.  
  131.  
  132.     <tr>
  133. <td>Applicable Cancellation Policy</td>
  134. <td>
  135.  
  136.  
  137. If cancelled or modified up to 3 days before date of arrival,  no fee will be charged.<br />
  138.  
  139. If cancelled or modified later or in case of no-show, 100 percent of the total price of the reservation will be charged.<br />
  140.  
  141.  
  142. </td>
  143. </tr>
  144.  
  145.     <tr>
  146. <td>Applicable Deposit Policy</td>
  147. <td>
  148.  
  149.  
  150. The total price of the reservation will be charged at least 2 days prior to arrival.<br />
  151.  
  152.  
  153. </td>
  154. </tr>
  155.  
  156.  
  157.  
  158.     <tr>
  159.     <td>Applicable Meal Plan</td>
  160.     <td>Breakfast is included in the room rate.</td>
  161. </tr>
  162.  
  163.  
  164. </table>"
  165.  
I would like <div class=""reservation-info"">
Name of Hotel · #603439460
</div> to be displayed either on my form Text3 or better still included in the table I am importing into Access. Any help would be appreciated. Thanks
May 31 '14 #1
0 1879

Sign in to post your reply or Sign up for a free account.

Similar topics

26
by: Charles Law | last post by:
Does anyone have a regex pattern to parse HTML from a stream? I have a well structured file, where each line is of the form <sometag someattribute='attr'>text</sometag> for example <SPAN...
13
by: DH | last post by:
Hi, I'm trying to strip the html and other useless junk from a html page.. Id like to create something like an automated text editor, where it takes the keywords from a txt file and removes them...
0
by: dodoG | last post by:
Hello, How to parse html file tags <h1>-<h4> to excel file with c#. 1. How i create excel 2007 object . 2. What should i do in visual studio 2005 (which references in com object). 3. How i...
0
by: rotaryfreak | last post by:
Hi, i previously worked on a program, written in c#, and a library was used to parse html. If i remember correctly, the library did two things: 1) it removed all html tags from the document and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.