我正在尝试解析访问VBA中的一些HTML代码。 html是查询中的记录,而不是文档中的记录,并且有数千条记录。
<div ><p class="note spec-note"><div><p >Lorem ipsum dolor sit amet,
consectetur adipiscing elit. Praesent feugiat gravida tincidunt. Cras
volutpat feugiat nisi eget vulputate. In tincidunt metus lorem, nec iaculis
mi semper ut.<p></div><div ><table><tr><th colspan="2"><span >General
Information</span></th></tr><tr><td >Brand Name:</td><td>Lorem<a
disabled="disabled" target="_blank"></a></td></tr><tr><td >Manufacturer:
</td><td>Lorem<a disabled="disabled" target="_blank"></a></td></tr><tr><td
>Manufacturer Part Number:</td><td>000-000-000<a disabled="disabled"
target="_blank"></a></td></tr><tr><td >Marketing Information:</td><td>Lorem
ipsum dolor sit amet, consectetur adipiscing elit. Praesent feugiat gravida tincidunt. Cras volutpat feugiat nisi eget vulputate. In tincidunt metus lorem, nec iaculis mi semper ut. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Duis ultricies iaculis facilisis. Aliquam sed nulla varius felis consequat sodales. Ut pellentesque libero ex, non mollis lorem luctus bibendum. Mauris odio sapien, consequat a ultrices in, pellentesque vel enim. Ut laoreet commodo tortor convallis gravida.<a disabled="disabled" target="_blank"></a></td></tr><tr><td >Package Type:</td><td>Bulk<a disabled="disabled" target="_blank"></a></td></tr><tr><td >Product Name:</td><td>Lorem<a disabled="disabled" target="_blank"></a></td></tr><tr><td >Product Type:</td><td>Ipsum<a disabled="disabled" target="_blank"></a></td></tr></table><table><tr><th colspan="2"><span >Miscellaneous</span></th></tr><tr><td >Additional Information:</td><td><ul><li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li><li>Lorem ipsum dolor sit amet, consectetur adipiscing elit!</li><li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li><li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li><li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li><li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li><li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li></ul><a disabled="disabled" target="_blank"></a></td></tr><tr><td >Certifications & Standards:</td><td><ul><li>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</li></ul><a disabled="disabled" target="_blank"></a></td></tr></table><table><tr><th colspan="2"><span >Physical Characteristics</span></th></tr><tr><td >Color:</td><td>Gray<a disabled="disabled" target="_blank"></a></td></tr></table><table><tr><th colspan="2"><span >Technical Information</span></th></tr><tr><td >Ipsum</td><td>250 ft<a disabled="disabled" target="_blank"></a></td></tr><tr><td >Cable Type:</td><td>Category 5e<a disabled="disabled" target="_blank"></a></td></tr><tr><td >Conductor:</td><td>Copper<a disabled="disabled" target="_blank"></a></td></tr></table><table><tr><th colspan="2"><span >Warranty</span></th></tr><tr><td >Limited Warranty:</td><td>Lifetime<a disabled="disabled" target="_blank"></a></td></tr></table></div></div>
到目前为止,这是我使用VBA代码的地方,我对VBA完全不熟悉。
Sub Extract_TD_text()
Dim db As dao.Database
Dim rs As dao.Recordset
Dim doc As HTMLDocument
Dim sku As String
Dim tbl As HTMLTable
Dim tds As IHTMLElementCollection
Dim td As HTMLTableCell
Dim r As Long
Set db = CurrentDb
Set rs = db.OpenRecordset("Query2")
Set doc = rs.Fields("Desc")
Set tds = doc.getElementsByTagName("td")
If Not (rs.EOF And rs.BOF) Then
rs.MoveFirst
Do Until rs.EOF = True
r = 0
For Each td In tds
Debug.Print td
r = r + 1
Next
Loop
End If
'ExitSub:
' Set rs = Nothing
' '..and set it to nothing
' Exit Sub
'ErrorHandler:
' Resume ExitSub
End Sub
我需要从描述字段中的每个html表中获取一个特定的行,其第一列包含“Marketing Information”,第二列是实际信息。然后将其内部文本放入元字段中。所有元字段必须与其各自的sku字段匹配。此外,它不一定是VBA任何有用的东西,但它必须是访问。我知道这很多,请任何帮助都很棒。
谢谢!