Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
231 views
in Technique[技术] by (71.8m points)

html - Conditional Statement that check the TABLE ID - ASP XML DOM

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.. :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...