Conditional Statement that check the TABLE ID - ASP XML DOM

谁说胖子不能爱 提交于 2019-12-13 04:46:40

问题


I have an HTML stored on the variable called textResponse coming from the other website and I also have a simple ASP-XML DOM code that check and output the table through className.

Here is the HTML structure

<html>
   <head></head>
     <body>
       <table id="mytable" class="results">
           <tr>
               <td>Some Data</td>
           </tr>
       </table>
     </body>
</html>

and here is the ASP and XMLDOM code that check and output the TABLE through class attribute

Dim HTMLDoc, XML
Dim URL, table

Set HTMLDoc = CreateObject("HTMLFile")
Set XML = CreateObject("MSXML2.ServerXMLHTTP")

URL = "www.sample.com" 
With XML
  .Open "GET", URL, False
  .Send
  HTMLDoc.Write .responseText
  HTMLDoc.Close
End With

For Each table In HTMLDoc.getElementsByTagName("TABLE")

If table.className = "results" Then
     tablestr = table.outerHTML
End If
Next

the code works perfectly fine but this time, i want to output the table using TABLE by ID attribute. Is there any other way to check and output the TABLE through ID attribute?


回答1:


I got the answers on my question by the way, atleast it will contribute to others who doesn't know yet

For Each table In HTMLDoc.getElementsByTagName("TABLE")
    If table.getAttribute("id") = "mytable" Then
        tablestr = table.outerHTML
    End If
Next

Hope it helps.. :)



来源:https://stackoverflow.com/questions/19508708/conditional-statement-that-check-the-table-id-asp-xml-dom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!